Jump to content

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?

 

 

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.