Strange session error

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Strange session error

Post by superdezign »

Well I'm still making this e-commerce website and I thought my system was finished until I did further testing. Guess what? I can't delete items consistently.

And I've got the weirdest thing. Look at this:

Code: Select all

$current = 0;
foreach($_SESSION['cart'] as $cartItem)
{
	echo $cartItem['qty']." ".$_SESSION['cart'][$current]['qty'];
	$current++;
}
Its printing "2 0." What's up with that??

I'm getting different values. I set it up so that deleting an item simply sets its quantity to zero, and ignores those items. Inefficient, I know, but unset() wasn't working properly. Now this isn't either.

Both methods worked sometimes, but not always. There's got to be a reason for this.
User avatar
Mordred
DevNet Resident
Posts: 1579
Joined: Sun Sep 03, 2006 5:19 am
Location: Sofia, Bulgaria

Post by Mordred »

Code: Select all

foreach($_SESSION['cart'] as $current=>$cartItem)
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

... *Gasp* Silly me.
Post Reply