homepage Welcome to WebmasterWorld Guest from 23.22.173.58
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
confirmation in array
reffik024

5+ Year Member



 
Msg#: 4179930 posted 9:25 pm on Jul 31, 2010 (gmt 0)

Soo, I have a list of order that show up on one page, called todays orders (for a delivery service). Currently, an order is posted to one table, goes to the "today's orders" page, and I'm trying to add a confirmation button at the end of each order in the array to add to another table. With the code below, it works with the first order in the list, but when I try to confirm the orders below it, nothing happens.

while($row = mysql_fetch_array($result)){
echo $row['NAME']. "<br />". $row['DRIVER'].;
echo "<form name='confirm' action='todaycomplete.php' method='post'><input type='hidden' name='name' value='$row[NAME]'><input type='hidden' name='driver' value='$row[DRIVER]'><input type='submit' value='Order Complete'></form>
</p>
<FORM>";


show it shows up for example:

John Doe
Driver Name
[Order Complete]

John Doe 2
Driver Name
[Order Complete]

John Doe 3
Driver Name
[Order Complete]

but only the first one works when you hit order complete.

 

Matthew1980

WebmasterWorld Senior Member 5+ Year Member



 
Msg#: 4179930 posted 5:37 pm on Aug 1, 2010 (gmt 0)

Hi there reffik024,

>>but only the first one works when you hit order complete.

Your calling this information from a database, populating the input type="hidden" fields and echoing to screen, so I presume that when you are submitting the form, you only receive 1 set of data opposed to three different sets (which I assume is what your expecting?).

Try this:-

$Counter = 0;
while($row = mysql_fetch_array($result)){
$Counter++;
echo $row['NAME']."<br />".$row['DRIVER']."\n\r";
echo "<form name=\"confirm\" action=\"todaycomplete.php\" method=\"post\">\n\r";
echo "<input type=\"hidden\" name=\"name".$Counter."\" value=\"".$row['NAME']."\">\n\r";
echo "<input type=\"hidden\" name=\"driver".$Counter."\" value=\"".$row['DRIVER']."\">\n\r";
echo "<input type=\"submit\" value=\"Order Complete\">\n\r";
echo "</form>\n\r";


The when you check the page source, you will see that each of the name attributes in the input tags will have a number attached (each loop generates a new number) this then makes the fields unique, then with that sorted, you can check on the receiver page, that the $_POST array (when you hit the submit button) will be populated as expected.

Hopefully I have understood your question correctly, but from the code you have posted, that seems to be the issue, you had the elements with static names.

Cheers,
MRb

reffik024

5+ Year Member



 
Msg#: 4179930 posted 6:48 pm on Aug 2, 2010 (gmt 0)

That worked! Thank you!

Matthew1980

WebmasterWorld Senior Member 5+ Year Member



 
Msg#: 4179930 posted 7:05 pm on Aug 2, 2010 (gmt 0)

Hi there reffik024,

Nice one. Glad your sorted :)

Cheers,
MRb

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved