almystersv Posted January 9, 2008 Share Posted January 9, 2008 Hi Guys, Im creating a mock up of a stationary ordering system and have the add to basket function working fine but the remove from basket is not working. Here is my code for removing items from the shopping basket.. <?php session_start(); foreach($_SESSION['basket'] as $key => $product) { if ($_SESSION['basket'][$key]['URN'] == $_GET['URN']) { unset($_SESSION['basket'][$key]); } } header("Location: StationaryMain.php"); exit(); ?> Any help on this would be brilliant, thanks Quote Link to comment Share on other sites More sharing options...
almystersv Posted January 10, 2008 Author Share Posted January 10, 2008 ...Any Help would be greatly appreciated! Quote Link to comment Share on other sites More sharing options...
harristweed Posted January 10, 2008 Share Posted January 10, 2008 I've no idea but the Manual says... session_unregister (PHP 4, PHP 5) session_unregister — Unregister a global variable from the current session might be worth swapping 'unset' for 'session_unregister' Quote Link to comment Share on other sites More sharing options...
almystersv Posted January 10, 2008 Author Share Posted January 10, 2008 hi, Thanks for taking a look. I tried your suggestion but it has made no difference! Quote Link to comment Share on other sites More sharing options...
DyslexicDog Posted January 10, 2008 Share Posted January 10, 2008 I have a similar problem with Session variables, I didn't look into it much so it would be nice if someone could come up with an answer for this one. Quote Link to comment Share on other sites More sharing options...
revraz Posted January 10, 2008 Share Posted January 10, 2008 Just checking, shouldn't if ($_SESSION['basket'][$key]['URN'] == $_GET['URN']) be if ($_SESSION['basket'][$key] == $_GET['URN']) Are you entering the IF loop? Echo out the array to make sure you are in fact getting to the unset command. Quote Link to comment Share on other sites More sharing options...
almystersv Posted January 10, 2008 Author Share Posted January 10, 2008 This made no difference. Just checking, shouldn't if ($_SESSION['basket'][$key]['URN'] == $_GET['URN']) be if ($_SESSION['basket'][$key] == $_GET['URN']) And Im not entirely sure how to echo an array to the screen...!? Thanks for your help. Quote Link to comment Share on other sites More sharing options...
revraz Posted January 10, 2008 Share Posted January 10, 2008 print_r($_SESSION['basket'][$key]) will echo the array contents, but you can see if it is getting there by just adding unset($_SESSION['basket'][$key]); echo "We ran the unset command"; Quote Link to comment Share on other sites More sharing options...
almystersv Posted January 10, 2008 Author Share Posted January 10, 2008 Hi, I commented out the header("Location: StationaryMain.php"); exit(); part of my code so it didnt keep returning to that page and input that piece of code u gave me that would output a message but no message appeared, so i take it it isn't getting to the if statement! Quote Link to comment Share on other sites More sharing options...
almystersv Posted January 10, 2008 Author Share Posted January 10, 2008 Hi Ive changed the code so now it empties the whole basket but not the products individually... <?php session_start(); foreach($_SESSION['basket'] as $key => $product) { if ($_SESSION['basket'][$key]['URN'] == $product['URN']) { unset($_SESSION['basket'][$key]); } } header("Location: StationaryMain.php"); exit(); ?> It does now get to the IF Statement though. Quote Link to comment Share on other sites More sharing options...
almystersv Posted January 10, 2008 Author Share Posted January 10, 2008 ...any idea on how i get it from removing all products in the shopping basket to just one!? Quote Link to comment 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.