PDA

View Full Version : making a shopping cart using php and MSQL


Trusten
08-29-2002, 09:22 PM
I wanted to make a shopping cart this way.

i figure, they click 'add me'

then it adds them to a database, right?
then remove me (i'm talking about the items), it takes it out of the database.

problem is, if i do that, how will i dentify someone if they are a guest?

I thought about making a session for each person, one that would assign them an id of sorts. Orrr, some way that when they add the thing to the cart, it'll be stored, and at the end of check out, they must enter their member info, or sign up to be a member, blah blah blah

that way, it'll know who made the oder.

later on, i wanted to use that information for an 'order status page', ya know?

um, anyhow, i would perfer not making chosen guest sign up but, *shrug* um, right now, it'd be good to.

any ideas?

Spookster
08-29-2002, 09:46 PM
It would be better to just store the items in the session verses the database. That way if a guest or member changes their mind and goes elsewhere or closes their browser the items get discarded being in the session instead of having a mess in the database storing temporary items.

Creating a shopping cart class is a way to do this:

http://www.codingforums.com/showthread.php?s=&threadid=2375

And as you said once they get through putting stuff in their cart they can login or register and just keep bringing the cart along to each page and once they have logged in then store it in the database when they want to check out. Or if you want to do it both ways you can check to see if they are logged in while they shop that way you can take them directly to the purchase page or if they haven't logged in take them to the login/register page. Meanwhile carry the cart along the whole way.

Trusten
08-29-2002, 09:49 PM
sounds good

but i'd rather NOT force a member sign up.

Trusten
08-29-2002, 09:52 PM
i looked at what you said, it sounds really good. but i am really new at php


any way you could show me an example of a script?

Spookster
08-29-2002, 10:03 PM
If they are a member then they either need to login before they start adding stuff to their cart or login after they are done adding stuff to their cart. So in simple terms:


When they are done shopping:

if(logged in){
Go to purchase page
}
else{
go to login/register page
then go to purchase page
}


Example of what script? There is an example a shopping cart script I wrote in the link to the thread I posted.

Spookster
08-29-2002, 10:11 PM
If you are new to php then it might be better to use a pre-written one. There are many free and commercial ones available:

http://www.hotscripts.com/PHP/Scripts_and_Programs/E-Commerce/Shopping_Carts/

Trusten
08-30-2002, 05:29 AM
is there any way to do it without them loggin in?
or signing up?

Spookster
08-30-2002, 06:12 AM
I'm confused. You want people to be able to buy stuff from your site without knowing who it was?

Trusten
08-30-2002, 07:43 AM
no,

well,

yes i suppose so.

but then again, i get address and stuff anyhow so i guess you are right.

i just didn't want to make it into a hastle for people to buy.