form post select tags

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
gisler87
Forum Newbie
Posts: 5
Joined: Fri Feb 19, 2010 11:43 am

form post select tags

Post 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
solid
Forum Commoner
Posts: 28
Joined: Wed Aug 12, 2009 11:56 am

Re: form post select tags

Post 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>";
}
gisler87
Forum Newbie
Posts: 5
Joined: Fri Feb 19, 2010 11:43 am

Re: form post select tags

Post by gisler87 »

HI,

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


Gisler
Post Reply