Hey, I am trying to write a system which will allow the user to update the quantity of products they wish to purchase.
It allows me to update the quantity of every single quantities incremented by a sinle value, but I cant have different items have different quantities.
Here is the code I'm using:
function get_quantity($id, $quantity) {
$quantity_array = array ("product_id"=> $id, "quantity"=> $quantity);
return $product_array;
}
if ($delete) {
$products_array = array_diff ($products_array, array ($delete));
}
if (isset($add)) {
$products_array[] = $add;
}
print "<br>";
print "<table border=0 align=center width=500 class=main>";
$products_array = array_unique($products_array);
foreach ($products_array as $id) {
if (!isset($quantity)) {
$quantity = 1;
}
$result = mysql_query("select * from products where id = $id");
while ($array = @mysql_fetch_array($result, MYSQL_ASSOC)) {
$myquantity = get_quantity($id, $quantity);
print "<tr><td>";
print "<form action='cart.php' action=POST>";
print "<table class=main><tr>";
print "<td>";
print "<b><u>".$array[name]."</u></b> | ";
$array[price] = ($array[price])*($quantity);
print "<i>$".$array[price]."</i><br>";
print "</td><td>";
print "Quantity: <input type='text' name='quantity' value='".$myquantity[quantity]."' maxlength=1 size=1>";
print "</td><td>";
print "<input type='submit' value='Update'></form></td></tr>";
print "<tr><td colspan=2>";
print $array[description]."</td></tr></table>";
print "</td></tr>";
}
}
print "<tr><td><a href='productindex.php?PHPSESSID=".$sessid."'>Keep Shopping</a></td></tr></table>";
[/B]
This is the URL:
http://www.peroxsys.com/store/productindex.php
Shop and add a few items to the cart, then change the quantity and see what I mean. Thanks for the help!