View Single Post
Old 03-04-2005, 12:18 PM  
calmlikeabomb
Confirmed User
 
calmlikeabomb's Avatar
 
Join Date: May 2004
Location: SW Palm Bay, Florida
Posts: 1,323
Ok, well let's try a using a session.

This can be your addcart.php or whatever.

http://www.name.com/add.php?id=6

Where 6 is the product we are adding to the basket.

Code:
session_start();// start the session

if (is_numeric ($_GET['pid'])) { // Check for a product ID.

	$pid = $_GET['pid'];// Product ID being added to cart

if (isset ($_SESSION['cart'][$pid])) {// don't allow user to add twice
echo '<p>This item has already been added to your shopping cart!</p>';
exit();
		
} else {// If the product isn't part of the session add it.
$qty = 1;
}

	// Add to the cart session variable.
	$_SESSION['cart'][$pid] = $qty;

}//end if check for a product
That variable will hold all of your product ID's and a quantity of 1.

If you want to allow the item to be added to the cart more than 1 time.
Find and Replace:

Code:
echo '<p>This item has already been added to your shopping cart!</p>';
exit();
with:
Code:
$_SESSION['cart'][$pid] +1;
You can use this variable on your view cart page to retrieve what's in the user cart session.
__________________
subarus.
calmlikeabomb is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote