View Full Version : view cart problem, i cant

08-28-2006, 02:48 PM
Hi guys

my website offers the user to customise their own car/motorbike number plate and then purchase it through paypal.

heres the website url http://www.mikesplates.com

so heres my problem

Ive got this shopping cart on my website that seems to be causing me a headache.

here goes....

If i was to be a customer and add some products to my cart and then contiue to shop. All is well. But if i was to carry on shopping and then decide to look at what products i have. When i click on the link to view my cart, its empty.But if i was to click add to cart they are all there, but not when i click on "view cart"

whats the problem?


Creative Insanity
08-28-2006, 07:40 PM
How are you tracking the carts? cookies? if so is the view link picking up the current session or cookie correctly?

08-28-2006, 10:37 PM
cheers for getting back to me.

hmm, i dont think ive assigned any cookies, what would a code as such look like?, i know it has some sort of tracking device on add to cart, as everytime i add a new product the ones i bought previously show.

hmmmm..aarrghh.headache alert im all confused.

08-29-2006, 08:22 AM
im guessing here (a stab in the dark) but im betting you had nothing to do with the development of this site regarding the php cart ?

so if i was to mention it could be a $_session issue then im guessing it would mean the same as if i said its a banana issue!

trying to get an idea of your level of experience before i can help you.

so 1 -10?

10 = proffessional developer
1 = never programmed in PHP before.

what level do you rate yourself. Be honest.

08-29-2006, 10:37 AM
lol, bout a 6 in honesty,

It look like a session ID, which iv forgotton to put in the php code on my page and then place $memberid=session_id(); in the rest of the pages.

i never knew these where referred to as cookies.

im trying,

i need to look into the shopping cart link well i know its missing something like member id should be there aswell.

i try dude, i try

08-29-2006, 10:44 AM
a session is data which can be accessed through out your session in the application

you can store this data in memory or in a file called a cookie which is saved to the client machine

dont get the two mixed up as they are created and accessed differently

08-29-2006, 10:51 AM
thats what confused me as ive never used cookies for this type of thing.


08-29-2006, 01:37 PM
the thing is you can club a cookie to death

a user can clear cookies so i only find them useful when wanting to remember a user when logging in and even then i wouldnt use them ! (if that makes sense)

dont use cookies to retain cart info

assign your sessions to memory then destroy them when finished

Creative Insanity
08-29-2006, 07:40 PM
The problem with sessions is that you cannot retain the info for a set period of time. But if you only want to retain the info per session then I agree with DJ.

08-29-2006, 09:58 PM
so have i opted for the wrong solution then?


Creative Insanity
08-30-2006, 12:09 AM
No not really if you don't want to retain info over a period of time. Sessions are fine for one time hits.

08-30-2006, 07:29 AM
CI is correct

session is best for holding cart info

Creative Insanity
08-30-2006, 09:24 AM
But in me saying that I use cookies, as it does help to remind the account holder that there cart still has items in it in case they just got distracted (IE: are married and have a nagging wife, oh how I know about that LOL) or simplly forgot.
If they delete their cookies then so be it, nothing gained.

08-30-2006, 09:28 AM
i would retain any cart info in a db but use AJAX to submit the cart

its cleaner i think

Creative Insanity
08-30-2006, 09:32 AM
Here is the connection script where I set up the cookies.. I have placed comments to help.

// This page contains the connection routine for the
// database as well as getting the ID of the cart, etc.

$dbServer = "localhost";
$dbUser = "user";
$dbPass = "password";
$dbName = "database";

function ConnectToDb($server, $user, $pass, $database)
// Connect to the database and return
// true/false depending on whether or
// not a connection could be made.

$s = @mysql_connect($server, $user, $pass);
$d = @mysql_select_db($database, $s);

if(!$s || !$d)
return false;
return true;

function GetCartId()
// This function will generate an encrypted string and
// will set it as a cookie using set_cookie. This will
// also be used as the cookieId field in the cart table
return $_COOKIE["cartId"];
// There is no cookie set. We will set the cookie
// and return the value of the users session ID

setcookie("cartId", session_id(), time() + ((3600 * 24) * 1));
return session_id();


08-30-2006, 10:07 AM
o ok, cheers guys for your comments and thanks for your help very nuch appreciated.