Jump to content

Adding items to cart


3raser

Recommended Posts

How do I make like this: Someone clicks on item one or two, and it adds it to the cart. So say I added Item One to my cart two times, and Item Two to my cart three times. The session should (this is what I want it to do) look like this: 1-1-2-2-2

 

I'm trying to achieve this via the explode function.

 

<?php

$item_1 = "Item One <a href='loops_test.php?add=1'>Add Item</a>";
$item_2 = "Item Two <a href='loops_test.php?add=2'>Add Item</a>";

if($_GET['add'] == 1 || $_GET['add'] == 2)
{
	$item = $_GET['add'];
	if($item == 1)
	{
		$item = 1;
	}
	else
	{
		$item = 2;
	}
	$generate_items = explode("-", $session);
	$_SESSION['items']=$generate_items;
}

echo $item_1."<br/>";
echo $item_2."<br/>";
echo $_SESSION['items'];

?>

Link to comment
https://forums.phpfreaks.com/topic/206168-adding-items-to-cart/
Share on other sites

Sorry, didn't look too much into your code after your comment:

 

So say I added Item One to my cart two times, and Item Two to my cart three times. The session should (this is what I want it to do) look like this: 1-1-2-2-2

 

Your IF block is totally redundant. Why store $item as 1 or 2, when you know $_GET['add'] is equal to that already?

 

Where is $session coming from? $item doesn't get stored at all in your code.

 

--

 

I think you need to plan this out a little more. Where do these product IDs (1 & 2) come from?

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.