Forum Moderators: coopster

Message Too Old, No Replies

shopping cart quantity update

my code doesn't update the quantity(shopping cart)

         

sanji41

5:54 am on Sep 14, 2010 (gmt 0)

10+ Year Member



hi guys!
i've written a shopping cart script, every thing is fine. but it cant update the quantity when i try to add another, and it also adds when the window refreshed. please help! here is the code::
>>that is the code for quantity..

<td><input type="text" id="quantity" name="quantity-<?php echo $_POST['quantity'];?><?php echo $row['id_products'];?>" size="5" value="<?php echo $_SESSION['cart'][$row['id_products']]['quantity'];?>"></td>

<td><?php echo "$" . $row['price'];?></td>
<td><?php echo "$" . $_SESSION['cart'][$row['id_products']]['quantity']*$row['price'];?></td>
</tr>
<?php


>>this is the session(same page)


if (isset($_POST['submit'])){
foreach($_POST as $key){
$key = explode("-",$key);
$key = end($key);
$key = explode("submit", $key);
$key = end($key);

if($_POST['quantity-'.$key] == 0){
unset($_SESSION['cart'] [$key]);
//echo "Unset session";
}else{
$_SESSION['cart'][$key]['quantity'] = $value;
//echo "Updated session";
}


}
}


please help.

enigma1

6:52 pm on Sep 18, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



where is the $value variable set? Is it via the $_POST['quantity'] ?

What you want to do is to add the new posted quantity to the session quantity to keep track of the total.

sanji41

1:21 am on Sep 19, 2010 (gmt 0)

10+ Year Member



thanks for the reply, I already fixed it. the problem is this:
foreach($_POST as $key){ it should be $key => $value..silly me :D
anyways hope someone will find this helpful.. thanks guys!