Jump to content

Recommended Posts

in regards to your code are you referring to the echoing of the elements displaying with a , (comma)?

 

When the session is empty, I get this (which is working):

http://i55.tinypic.com/2mwcifm.png

 

.. but when I add a product using that hyperlink, I get this:

http://i52.tinypic.com/2r26sut.png

Actually, ignore that.

First, the size key in your session has a typo, it says 'side'

Also the variables for your ID and SIZE are not being set, these will need to be set, pretty much the same way you did in your original code.

 

Code (now the the added feature of comments)

<?php

session_start();
// I have also added in a check for the ID, no point adding something if you dont have a product associated to it //
if (isset($_GET['action']) && isset($_GET['size']) && isset($_GET['id']) && $_GET ['action'] == 'add') {
$size = $_GET['size']; // Get the size from the URL
$id = intval($_GET['id']); // Get the ID

// Add it to the cart
$_SESSION['cart']['content'][] = array('size' => $size, 'id' => $id);
}
// check if the cart is empty
if (empty($_SESSION['cart']['content'])) {
echo "No product in cart.";
} else {
// output a little message telling them how many products they have
echo "You have " , count($_SESSION['cart']['content']) , " products in your cart<br/>";
// loop through the products and display them
foreach ($_SESSION['cart']['content'] as $content) {
	echo "{$content['id']}, {$content['size']}";
}
}

?>

Ahh shit so I did make a typo!

 

Fantastic it worked! Thanks heaps for that.

 

I've been on the computer for 14 hours straight and haven't showered for frick 27 hours. I think its time to go and have one an jump on my BMX and ride and just forget about silicin chips and remember who I am.

I'm going to read over everything that has been discussed in this thread in full tomorrow when I am in a normal state of mind. Now I'm not all with it.

 

Thanks again. It really meant allot to me. (Y)(Y)

Dumbest apology ever.

 

Ahh shit so I did make a typo!

 

Fantastic it worked! Thanks heaps for that.

 

I've been on the computer for 14 hours straight and haven't showered for frick 27 hours. I think its time to go and have one an jump on my BMX and ride and just forget about silicin chips and remember who I am.

I'm going to read over everything that has been discussed in this thread in full tomorrow when I am in a normal state of mind. Now I'm not all with it.

 

Thanks again. It really meant allot to me. (Y)(Y)

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.