Jump to content

Remove from cart help!! (removing stuff from a session)


Recommended Posts

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.

 

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!

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.