I have a page that people can put in different amount of quanities for certain products. Here is the code for that page (in this example there are two products):
$qry = "Select * from products";
$result = mysql_query($qry);
?>
<form action="addtocart.php" method="post">
<table border="1">
<?
while($resultset = mysql_fetch_array($result)){
echo "<tr><td><b><i>".$resultset['name']."</b></i><br>".$resultset['desc']."</td><td valign=\"bottom\">".$resultset['price']."</td><td valign=\"bottom\"><input type=\"text\" name=\"quanity\" value=\"0\" size=\"3\"><input type=\"hidden\" name=\"id\" value=\"".$resultset[id]."\"><input type=\"hidden\" name=\"price\" value=\"".$resultset[price]."\">";
}
?>
</table><br><br>
<input type="submit" value="Update Cart">
</form>
So the price and the quanity fields can have multiple values. This page posts to this page:
include "config.php";
$quanity = $_POST['quanity'];
$productid = $_POST['id'];
$price = $_POST['price'];
for($i=0;$i<sizeof($productid);$i++){
echo "The quanity is: $quanity[$i]<br>";
echo "The price is: $price[$i]<br>";
$total = $quanity[$i] * $price[$i];
echo "The total is: $total<br><br>";
}
I thought it would display the quanity and the price is twice but for some reason it only runs through the loop once even though there are atleast two values being passed over. I thought the $_POST[] just keeps storing the variables and assigns them to $quanity or $price etc, then you can loop through like I did above to print out those variables. Doesn't seem to work though, anyone have any ideas to help??
Thanks for the advice in advance.