View Full Version : Shopping cart info

05-12-2004, 06:51 PM

i am making a shopping cart but got stuck on what i should use to store the values,

e.g. name and price of multiple items

should i store this all into a string or something else

any help appreciated

05-12-2004, 08:29 PM
I think your best bet would be to use sessions.

05-12-2004, 08:50 PM
sessions would be easiest but how would i set the multiple items

at the moment i have:

$_SESSION['name'] = 'Guitar<del>15.99'

to set the value (these are set from a get)

and i have

@list($name, $price) = explode("<del>", $_SESSION['name']);

echo $name;
echo $price;

to view it but this will only handle 1 item, how would i expand this?

Thanks for any help.

05-12-2004, 09:03 PM
Hopefully this will help...

Use arrays to hole the quantity, itemID (sku) and what ever else. See example:

<a href="page2.php">See session info</a>

Now on the second page (page2.php) I can print them out (or modify them if I want...

print "<pre>";
print "</pre>";

Hope this helps.

05-12-2004, 09:07 PM
Or, on page 1 you can even do this...

<a href="page2.php">See session info</a>

05-12-2004, 09:23 PM
last questions for now,

what does the <pre> bit do?

and how would i view the information on its own without the layout around it?

thanks for all the help. :thumbsup:

05-12-2004, 09:42 PM
Why don't you immedeately write it to the db or to a persistent cookie?
Otherwise all info is lost when the session is terminated.

You'll need to write it to the db sooner or later so why first drag it along in a session-variable?

05-12-2004, 09:46 PM
i'm not using a db but how would i do a similar thing and write it to a cookie

thanks for any help.

would i just be able to swap the session for cookie and is there an easy way to just roll off all the arrays of the cookie in a list

05-12-2004, 10:12 PM
wait a minute.

If you don't use a db and would store it inside a cookie or session, how do you then get the bought items? I hope you're not planning on have them mailed to you.
You do realise that yu don't have control over the session and cookiedata? The sessiondata is just removed when the session end, and the cookie is stored on the client.

Storing i in a cookie is as simple as

setcookie ('selected', $array_shoppigcart, time()+31536000); // expires after 1 year

to get the data:


$array_shoppigcart is then the array with your products

05-12-2004, 10:34 PM
what i am going to do is store it through the session and then it will be saved to a db properly when the customer goes to the checkout so that i am not saving data that does not come out to an order.

sorted it now so thanks everyone for the help


EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum