I am trying to make a shopping cart using PHP and mySql.
When I select a product, it adds to the table in the shopping cart okay, but whenever I want to add another product, it REPLACES the product in the cart. In other words, I can only have one product in the cart.
I thinh I need to use FOREACH, but I don't know how.
Some of my code is:
foreach($cart as $key => $value) {
$query = "select product_id, product_name, unit_price,
unit_quantity from products where product_id=\"$key\"";
$result = mysql_query($query) or die ("Product not available.");
if ($value > 0){
while (list($pid,$pname,$pprice, $pqty) =
mysql_fetch_row($result)) {
print "\t<tr>\n";
print ("\t\t<td>".$pname."</td>\n");
print ("\t\t<td>$".$pprice."</td>\n");
print ("\t\t<td>".$pqty."</td>\n");
print ("\t\t<td>".$value."</td>\n");
I am very new to PHP and programming.
MANY THANKS