I’m having some problem with the “delete” of my shopping cart script (is a case of a switch)
case 'delete':
if ($cart) {
$items = explode(',',$cart);
$newcart = '';
foreach ($items as $item) {
if ($_GET['id'] != $item) {
if ($newcart != '') {
$newcart .= ','.$item;
} else {
$newcart = $item;
}
}
}
$cart = $newcart;
$_SESSION['cart'] = $cart;
}
break;
Example: $_SESSION[‘cart’] = 1,2,1;
The problem is that when a client bought twice the same item, it deletes both. How can i fix it?
You need to set a flag, something like: