Connecting Tech Pros Worldwide Help | Site Map

unset() is not unsetting!

 
LinkBack Thread Tools Search this Thread
  #1  
Old July 17th, 2005, 04:20 AM
Xerxes
Guest
 
Posts: n/a
Default unset() is not unsetting!

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.




  #2  
Old July 17th, 2005, 04:20 AM
Xerxes
Guest
 
Posts: n/a
Default Re: unset() is not unsetting!

"Xerxes" <ashkaan57@hotmail.com> wrote in message
news:21475b9193766a5eb5562f5530561c5b@news.teranew s.com...[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[/color]
can[color=blue]
> be changed to add/remove an item:
> echo '<input type = "text" name = "'.$itemid.'" value = "'.$qty.'"[/color]
size[color=blue]
> = "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[/color]
submitted.[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
> if($new_qty == 0) // Removing item?
> {
> // Search the cart for items dependent on the item being[/color]
removed[color=blue]
> 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[/color]
4000,[color=blue]
> 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[/color]
value[color=blue]
> of the cart['itemid'] is unset but for some reason it is still there;
> that particualr item keeps showing up.
>
> Thanks for your help.
>[/color]

Never mind about this issue (or non-issue), it was caused by a stupid
logic problem!


  #3  
Old July 17th, 2005, 04:21 AM
Pedro Graca
Guest
 
Posts: n/a
Default Re: unset() is not unsetting!

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 :
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,989 network members.