Jump to content

Retrieving a value from a drop down box


jay_bo

Recommended Posts

Right okay, The code below pulls data from a mysql table and it displays the products available to purchase... I have done a while loop to display all the products and i have also done another while loop so that i can use a drop down box to select Small, Medium and Large which each have the vaule of its product id...However when i go to purchase the first product on the page and I click on the button to add to cart, it adds the last product on the page instead...heres my code...

 

echo'<form name="form1" method="post" action="myscript.php">';
$cat=$_GET['cat'];
if ($cat!="")
{
		$result=mysql_query("SELECT * FROM products WHERE cat_id=$cat");
		while($row=mysql_fetch_array($result)){
		  	
				    echo'<input type="hidden" name="command" />';
echo '<br />';
echo '<div id="item_container">';
echo '<div id="item_picture"><a href="'.$row["picture_large"].'" class="thickbox" rel="album" ><img src="'.$row["picture"].'" border="0" alt="'.$row["image_alt"].'"></a></div>';
echo '<div id="item_title"><h2>'.$row["name"].'</h2></div>';
echo '<div id="item_text"><p>'.substr($row["description"], 0, 100).'</p><br /><br />';
$type=$row["type"];
echo '<select name="productid">';

$sql="SELECT * FROM products WHERE type=$type";
						$result2 =mysql_query($sql);
						while ($row=mysql_fetch_assoc($result2)){
echo'<option value ='.$row["serial"].'>'.$row["price"].'</option>';

}
echo '</select>';
echo '<br /><br/>';
echo '<input type="submit" value="Add to Cart"/></span>';
		echo '</div>';
		echo '<br />';
		echo '<br />';
echo '</div>';
}
}
echo '</form>';

 

and on myscript.php all it does is outputs what the dropdown list was selected


<?PHP
include("includes/db.php");

$pid=$_POST['productid'];	

echo $pid;
?>

 

Many thanks

Link to comment
https://forums.phpfreaks.com/topic/197737-retrieving-a-value-from-a-drop-down-box/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.