Making a shopping cark with MySQL and PHP

Good morning,

We have an online bookstore. We are interested in having a shopping cart, where customer can select items and then pay for the total.

My question is about variable and tables definition.

These are the tables we have so far:
Products: books details
Customers: customers information
Cart: books selected by the customers
Orders: to consolidate orders

The idea of the website is as any other:
When a customer enters and selects a book, information is stored in a Cart table in MySQL, creating one new line in the table per each new book selected.
After selections are ready, customer makes checkout process and enter personal information.

My question is how can I store books selected from each customer if I do not have her/his personal information yet?
I mean, only when the customer makes checkout process I am able to get personal information, store in DB and get a CustomerID to identify him/her.

thanks a lot!!!

Session variables. Give the session a LONG timeout (like an hour instead of 20 minutes) and store all items the customer selects in the session scope (it will stay with the user from page to page.)

At checkout, grab all items from the session scope, calculate, etc.

HTH

Fantastic, thanks a lot!!

Don’t forget to clear out the session after checkout. :slight_smile: I’ve been bit in the undercarriage by forgetting that part.

Not sure if PHP can do it, but in ColdFusion you can create scopes within the session scope like so:
<cfset session.shcart = “” />
<cfset session.shcart.cart1 = “” />
<cfset session.shcart.cart1.item1 = “A book” />
<cfset session.shcart.cart1.item2 = “Another book” />

That way it’s easier to clear out one portion of the session when the checkout is done.
<cfset StructDelete(session,“shcart.cart1”) /> Will destroy ONLY cart1; if there is a cart2 or cart3, they will be left alone.

I’m sorry, I am not familiar with ColdFusion.
I will try to do it using PHP.

It’s been many, many years since I’ve worked with ColdFusion, but it looks like in PHP it would be something like
$_SESSION['shcart']['cart1']['item1']