Welcome to WebmasterWorld Guest from 54.163.35.238

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

confirmation in array

     

reffik024

9:25 pm on Jul 31, 2010 (gmt 0)

5+ Year Member



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

5:37 pm on Aug 1, 2010 (gmt 0)

WebmasterWorld Senior Member 5+ Year Member



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

6:48 pm on Aug 2, 2010 (gmt 0)

5+ Year Member



That worked! Thank you!

Matthew1980

7:05 pm on Aug 2, 2010 (gmt 0)

WebmasterWorld Senior Member 5+ Year Member



Hi there reffik024,

Nice one. Glad your sorted :)

Cheers,
MRb
 

Featured Threads

Hot Threads This Week

Hot Threads This Month