Before you start (please read!):Just to make sure you doesn't waste your time on this tutorial some things you need to know first.
When you want to start with this tutorial you should know how to use sessions and cookies. You should also have a user system. Making a shopping cart is very easy, but always a hurdle. It's always good to set up a good plan. This because you want to make sure that it fits your costumer needs. Not everyone will need a lot of functions. Just saving, ordering and listing products is enough for most of the e-commerce websites.
Sometimes you see a shopping cart that doesn't requires to log-in. When the user clicks to buy the products they will be asked to log-in. In this tutorial we won't make that. Not because it's to hard to make, but because it can be irritating and most of all confusing for your costumers.
First step (setting up your database)Users ('users') table:Next to all the information you store for users you should have the following cells in you user table.

It's not a problem if the fields have a different name. Just make sure that you can remember the names that are used. Do not throw different languages through each other. Also look out with HEADCASE and lowercase names.
Products ('products') table:After this check we need to create an effective database structure. When I started to write this tutorial I encountered a huge problem. There are no products to test it on for me. So now we will need to make a table for our products. If you already have one, just make sure that the most important fields are inside of your table. You can also add a field for product information.
Click here for the imageAgain this is just a example. You can add fields if you want more functionality. Just make sure you save a percentage the same way as I do (X / 100). Just to make it easier in the future to calculate the price with discount. Also it’s smart to save taxes in a different table. When taxes change you will only have to change 1 field.
Taxes ('taxes') tableJust a small table. The 'id' is the same as the taxes id in the product table.

Shopping cart ('shoppingcart') table:
Click here for the imageJust take a good look at this table. And try to link the 'pid' and 'uid' to the right table (just to make sure you know what you are doing). You will also need to save the date and time! You will not be using this for the payment. Because a user can wait a couple of days before sending the order. This date will give users the ability to look back at orders they have made. Even if you are not going to use it, it is still smart to save it. Because you will not be able to add this in the future if there are already products in the database.
The check field is for checking if the product is already ordered or not. I prefer to use for true a '1' and for false a '0'.
Please, check everything before you go on with the following step.
Second step (inserting products into the shopping cart)Now we are going to try to make everything work. You will need to do a lot yourself. I will not write the script for you, because you won't learn anything if I do that. Maybe you are already able to go on for yourself. The hardest part is done for you in the previous step, just make sure that you make a good documentation. Just like I did in Excel. These projects will take more then one day and you don't want to start all over again.
Ok, let's move on. You should first make a page that shows the products. In this page you can place an order form that goes to a page that inserts the product in the shopping cart. Just take a look at a existing e-commerce website. The form requires two fields. In the first field the user can set the amount of products. I used the name 'amount' for the amount of products that is going to be ordered. The other field is a hidden field where you can store the product id ('pid'). A button will submit the field. The handling page should look like this:
CODE
INSERT INTO shoppingcart (pid, uid, amount) VALUE ('" . $pid . "', '" . $uid . "', '" . $amount . "')
The field 'uid' is the id of the user (probably from a session). The date and time shouldn't be inserted yet! Like I've said before, that's the date and time the user orders the product not the date and time of placing it in the shopping cart.
If you're able to insert products into your shopping cart you can make the shopping cart itself. The shopping cart is the page that shows the products that is in the user's list. The select query will look like the one below:
CODE
SELECT * FROM shoppingcart WHERE uid = '" . $uid . "' AND check = '0'
Make sure that the user can do three things in his shopping cart: Edit, delete and ordering the products.
Last step (products check out)When the user makes the decision to buy the products he can go to his shopping cart and click on a large order button. Behind the order button will be a php script that handles this check out. The php file that handles the check out will do a couple of things:
1. Notifying the owner of the shop that there are products ordered. This can be done by e-mail, but you can also choose for an admin page. The admin page will show which products are ordered, the date of the order and the user that ordered the product. You can use the existing shopping cart table for this page. Off course you can also send all these information to a mail box, but you'll get in trouble if there are to many orders.
2. Updating the ordered products. Setting 'check' to 1, 'date' and 'time'.
3. Confirming the order by sending an e-mail to the user.
I'll hope this third tutorial is very usefull for you, as designer. I've rewritten the last 2 steps for three times I hope it's clear now. Just open a new topic here if you need any help.