RE Viewing Session Varibles
| From: | neil smith | Date: | Fri, 08 Feb 2002 10:05:26 +0000 |
| Subject: | RE Viewing Session Varibles | ||
| Groups: | php.db | ||
| Request: | Send a blank email to php-db+get-16658@lists.php.net to get a copy of this message | ||
Seems to me that the problem might be in the logic (correct me if I'm wrong - likely - but...)
In these lines :
foreach ($cart as $id => $qty)
{
if ($$id == "0")
{
unset ($cart[$id]);
.....
[snip]
You unset $cart[$id] if $$id==0. Now, if you are using numeric array indexes, then for example $id might be '12' (number or string, it don't matter). So what you're asking of php is to get $$id, that works out as $12 , which I guess is not a variable name.
Not being a variable it will return false (or zero) and so $$id=="0" will be true, your if statement executes and unsets the value for $cart[$id], which *is* a valid variable name. Could you replace $$id==0 with isset($$id) and see if you get the same results?
Cheers,
Neil Smith.
At 20:57 07/02/2002 +0000, you wrote:
From: Robert Weeks [mailto:robert@woozy.com] Sent: Thursday, February 07, 2002 10:41 AM To: php Subject: Re: [PHP-DB] Viewing Session Varibles Ok, This is driving me nuts. I'm sure its something simple but I can't seem to find the glitch. I'm trying to make a simple shopping cart using Session varibles to store the item => quantity pairs, then I loop thru the cart and query the db to get the item details, etc.. Most of it works fine but whenever I add a new item to the cart I lose the $qty value for the other items.