jayskates Posted October 15, 2009 Share Posted October 15, 2009 Hey guys, I'm new to the forums and was wondering if anyone could give me a helping hand... I am trying to build a shopping cart application, and i've been stuck on the remove item from cart for a few days now... Right now I have a product list page, which displays all the products, and on that page you can click add to cart on any product and it will store that product info in the session. I then have an add product.php page which is just a script that stores the information that was sent from the product list page. Then on the view cart page, I am displaying the products that were added to the cart (session). The problem I am having is I am not able to figure out how to remove an item from the cart, or session for that matter. I'm using a separate page for the remove item. The code on the remove_item.php page is as follows: <?php session_start(); if(!isset($_SESSION['purchases'])) { //"!isset" means if it is NOT set $newitem = "item".$_SESSION['purchases']; $newprice = "price".$_SESSION['purchases']; $newname = "name".$_SESSION['purchases']; $newimg = "image".$_SESSION['purchases']; $_SESSION[$newitem] = $_GET['productnumber']; $_SESSION[$newprice] = $_GET['productprice']; $_SESSION[$newname] = $_GET['productname']; $_SESSION[$newimg] = $_GET['productimg']; }else{ $newitem = "item".$_SESSION['purchases']; $newprice = "price".$_SESSION['purchases']; $newname = "name".$_SESSION['purchases']; $newimg = "image".$_SESSION['purchases']; $_SESSION[$newitem] = $_GET['productnumber']; $_SESSION[$newprice] = $_GET['productprice']; $_SESSION[$newname] = $_GET['productname']; $_SESSION[$newimg] = $_GET['productimg']; $_SESSION['purchases']--; } So the session everythings being stored in is "purchases" , and i'm getting the information from the url i sent to this page with $_GET[] . Right now, when I click any remove from cart, it will always remove the last thing in the session from the page, but it doesn't remove it from the session. I know I need to use unset, or at least i'm pretty sure I do, but i'm not sure how. If anyone can understand what I just said, any help would be greatly appreciated!!! Thanks in advance to any replies, Jay. Quote Link to comment https://forums.phpfreaks.com/topic/177823-remove-from-cart-help-removing-stuff-from-a-session/ Share on other sites More sharing options...
mikesta707 Posted October 15, 2009 Share Posted October 15, 2009 unset($_SESSION['purchases']['Purchase to Remove']); ? Quote Link to comment https://forums.phpfreaks.com/topic/177823-remove-from-cart-help-removing-stuff-from-a-session/#findComment-937635 Share on other sites More sharing options...
jayskates Posted October 15, 2009 Author Share Posted October 15, 2009 unset($_SESSION['purchases']['Purchase to Remove']); ? Thanks for the reply mikesta, When I try this, it just adds another value to the end of the session, and then every time i click on any remove item from cart it just swaps that item with the one i clicked on. I am royally confused! Quote Link to comment https://forums.phpfreaks.com/topic/177823-remove-from-cart-help-removing-stuff-from-a-session/#findComment-937642 Share on other sites More sharing options...
jayskates Posted October 15, 2009 Author Share Posted October 15, 2009 bump! Quote Link to comment https://forums.phpfreaks.com/topic/177823-remove-from-cart-help-removing-stuff-from-a-session/#findComment-937666 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.