Hello

I am trying to create a shopping cart. I am storing the cart details in an object with functions such as 'addtocart', etc.

The problem that I am stuck on at the moment is that I am trying to determine if this is the first time the cart has been created to determine if to create a new instance of the class or to use the current cart object to add new items to i.e $cart-addtocart(??)

Below is the code where I trying to determine of the

include_once('libs/cart.php');

$cart = unserialize($_SESSION['cartid']);
if(isset($cart)
{
	echo "here";
	$cart = unserialize($_SESSION['cartid']);
} else {	
	echo "herenow";
	$cart = new Cart();
}

$cart->addToCart($jewelID,$image,$price,$name);
}

The problem at the moment is that it keeps meeting the first condition and thinks that the cart object 'cartid' has been set when i first run the program

This is very new to me, and have been looking around to see how to best to resolve this.

Any help would be fully appreciated

Thanks
Ian

    On the row above you set the cart, so it is set. Try to remove that line and instead check if $_SESSION['cartid'] is set or not.

      Thanks Piranha

      That does now go to the second part of the condition and should create the new object. I am having a few problems with my sessions and storing the object, but this is a seperate issue which I will have a play around with.

      Thanks again for your advice

      Ian

        Write a Reply...