Hi,
I have a cart, setup as an associative array (itemid=>qty). When the
cart is displayed, the quantity field is an input box and the value can
be changed to add/remove an item:
echo '<input type = "text" name = "'.$itemid. '" value = "'.$qty.'" size
= "3">';
when the "Save changes" button on the page that displays thecart is
pressed, a hidden field called "save" is set and the form is submitted.
session_start() ;
if(isset($_POST['save']))
{
foreach ($_SESSION['cart'] as $itemid => $qty)
{
$new_qty = $_POST[$optionid]; // I used (int)
$_POST[$optionid], didn't help
if($new_qty == 0) // Removing item?
{
// Search the cart for items dependent on the item being removed
if (!($result = check_required( $optionid,
$_SESSION['builderid']))) { // this function returns FALSE
unset($_SESSION['cart'][$optionid]);
unset($_SESSION['optionid']);
}
.....
}
}
This things seems to go into an infinite loop. It unsets, say item 4000,
then goes back and tries to remove it again, and again. I used
error_log() function to see what is going on and it seems that the value
of the cart['itemid'] is unset but for some reason it is still there;
that particualr item keeps showing up.
Thanks for your help.
I have a cart, setup as an associative array (itemid=>qty). When the
cart is displayed, the quantity field is an input box and the value can
be changed to add/remove an item:
echo '<input type = "text" name = "'.$itemid. '" value = "'.$qty.'" size
= "3">';
when the "Save changes" button on the page that displays thecart is
pressed, a hidden field called "save" is set and the form is submitted.
session_start() ;
if(isset($_POST['save']))
{
foreach ($_SESSION['cart'] as $itemid => $qty)
{
$new_qty = $_POST[$optionid]; // I used (int)
$_POST[$optionid], didn't help
if($new_qty == 0) // Removing item?
{
// Search the cart for items dependent on the item being removed
if (!($result = check_required( $optionid,
$_SESSION['builderid']))) { // this function returns FALSE
unset($_SESSION['cart'][$optionid]);
unset($_SESSION['optionid']);
}
.....
}
}
This things seems to go into an infinite loop. It unsets, say item 4000,
then goes back and tries to remove it again, and again. I used
error_log() function to see what is going on and it seems that the value
of the cart['itemid'] is unset but for some reason it is still there;
that particualr item keeps showing up.
Thanks for your help.
Comment