Xerxes wrote:[color=blue]
> 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.
>[/color]
turn on error reporting:
error_reporting(E_ALL);
ini_set(diplay_errors', '1');
[color=blue]
> session_start();
> if(isset($_POST['save']))
> {
> foreach ($_SESSION['cart'] as $itemid => $qty)
> {
> $new_qty = $_POST[$optionid]; // I used (int) $_POST[$optionid], didn't help[/color]
What is $optionid ?
[color=blue]
> 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]);[/color]
Changing the array that controls the loop inside the loop ?
I don't like it, but guess it's ok.
[color=blue]
> 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.[/color]
Perhaps you're mixing $optionid with 'optionid'
or $optionid with $itemid
--
USENET would be a better place if everybody read: : mail address :
http://www.catb.org/~esr/faqs/smart-questions.html : is valid for :
http://www.netmeister.org/news/learn2quote2.html : "text/plain" :
http://www.expita.com/nomime.html : to 10K bytes :