RynMan Posted June 12, 2010 Share Posted June 12, 2010 Hey guys! I'm trying to work through my shopping cart here and am having a problem. Everytime I start up a new session (clear my cookies in firefox) and start testing, I get the following error.... Notice: Undefined variable: cart in C:\wamp\www\Adept\action_handle.inc.php on line 16 It's pointing to my code here.... session_start(); $cart = $_SESSION['cart']; $action = $_GET['action']; $iquantity = $_POST['iquantity']; I'm guessing it's because the session has just started so naturally there will be nothing in the 'cart'. How is this usually avoided? Do we need to assign something to the cart to start with? I'm trying not to do that, as my cart counts the number of instances a number (ID) appears....so I can't really have any values in there to start. Thanks for any help! Quote Link to comment https://forums.phpfreaks.com/topic/204576-session-variable/ Share on other sites More sharing options...
kenrbnsn Posted June 12, 2010 Share Posted June 12, 2010 Do something like this: <?php session_start(); $cart = (isset($_SESSION['cart']))?$_SESSION['cart']:''; $action = $_GET['action']; $iquantity = $_POST['iquantity']; ?> This will assign a 0 character string to $cart if there is no 'cart' session variable. If there is one, $cart will be assigned it's value. Ken Quote Link to comment https://forums.phpfreaks.com/topic/204576-session-variable/#findComment-1071159 Share on other sites More sharing options...
RynMan Posted June 13, 2010 Author Share Posted June 13, 2010 Do something like this: <?php session_start(); $cart = (isset($_SESSION['cart']))?$_SESSION['cart']:''; $action = $_GET['action']; $iquantity = $_POST['iquantity']; ?> This will assign a 0 character string to $cart if there is no 'cart' session variable. If there is one, $cart will be assigned it's value. Ken Awesome! Thanks Ken! Quote Link to comment https://forums.phpfreaks.com/topic/204576-session-variable/#findComment-1071312 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.