Page 1 of 1

form post select tags

Posted: Mon Apr 12, 2010 5:19 pm
by gisler87
Hi,

i have a page that displays a table of the the products purchased for an order. i want to use a drop down box so that you can change the status of the purchased product from processing to dispatched. I then have an update button that should submit all the products status.

I am however having trouble of knowing how i catch all the posts for each products status.

here is my code

Code: Select all

 echo "<form id='dis' name='dis' method='post' action='dis-exec.php'>";
			 $results=getOrderdetails($id);
			 $nums = mysql_numrows($results);
			 $x=0;
			 while ($x<$nums){
			
			$pid=mysql_result($results,$x,0);
			$prname=mysql_result($results,$x,2);
			$stock=mysql_result($results,$x,6);
			$qty=mysql_result($results,$x,10);
			$status=mysql_result($results,$x,11);
			echo "<tr>";
				echo "<td>$pid</td>";
				echo "<td>$prname</td>";
				echo "<td>$stock</td>";
				echo "<td>$qty</td>";
				echo "<td><select name='state'>
				  <option>$status</option>
				  <option>Dispatch</option>
				</select></td>";
			echo "</tr>";
         	 echo "<input type='hidden' name='pid' value='$pid'>";
      		 echo "<input type='hidden' name='orid' value='$oid'>";
        	$x++; 
        	}
      		 echo "</table>";
      		
      		 echo "<input type='submit' value='Update'>";
      		 echo "</form>";

from what i have been found this bit of code will allow me to catch all the posts of the select tag but it seems to only catch one, the last one in the table.

Code: Select all

foreach ($_POST as $value) {
echo "$value<br>";
}
many thanks

gisler

Re: form post select tags

Posted: Mon Apr 12, 2010 9:18 pm
by solid
Each tag needs to have a unique 'name'. You can use an array. Instead of:
name="state" for product 1
name="state" for product 2
name="state" for product 3
use:
name="state[0]" for product 1
name="state[1]" for product 2
name="state[2]" for product 3

Then access the values like this:

Code: Select all

foreach ($_POST['state'] as $value) {
echo "$value<br>";
}

Re: form post select tags

Posted: Tue Apr 13, 2010 2:09 am
by gisler87
HI,

Thanks for the help, that worked like a treat. :D


Gisler