How to Build Shopping Cart w/ Checkout in PHP

Language

I just rewrite the code included in this post to fix minor problem encounter by other PHP programmers who can’t run the shopping cart.

The code is taken from this link: http://www.qualitycodes.com/tutorial.php?articleid=25&title=Tutorial-Building-a-shopping-cart-in-PHP.

As you may have noticed, a lot of programmers are screaming for help on how to fix some bugs on this tutorial. Since I cannot upload the code in the said website, I decided to post it here. Still credit goes to “Richard Clark”.

Changes on the code are following:

  1. Change “<?” to “<?php” to handle php correctly. Some old program still uses “<?” to run PHP code. However, PHP 5 is not stricter and requires you to use php after <?, unless you configure Apache to allow such a shorthand support.
  2. Add echo command instead of equal (=) sign.

Note: If you run the code prior to downloading this code, make sure to clear your browser cache.

Note: Due to the size or complexity of this submission, the author has submitted it as a .zip file to shorten your download time. After downloading it, you will need a program like Winzip to decompress it.

Virus note: All files are scanned once-a-day by SourceCodester.com for viruses, but new viruses come out every day, so no prevention program can catch 100% of them.

FOR YOUR OWN SAFETY, PLEASE:

1. Re-scan downloaded files using your personal virus checker before using it.
2. NEVER, EVER run compiled files (.exe's, .ocx's, .dll's etc.)--only run source code.

Comments

Hello, I've tried uploading the files directly to my web server, but it still produces errors and not the shopping cart. Is there something I should be doing differently such as uploading the sql file elsewhere?

sir thanks for this awesome tutioral....i realy appreciate you but i have a problem......i have three product categories....so i had used three products table,three products page, 3 shopping cart pages.......but the problem when only one product works ........but when i open second page.........nd select add to cart........shopping cart does not get name,price,description...only show quantinty and serial.........other fields remain blank...........although other option like update,clear,and remove is working properly..............please help me :(

this was extremely helpful. I am trying to make my first e-comm project.. it was a great help. thanks.

Thanx!! a lot for this readymade scripting of shopping cart.. Thanx........

hi...can you explain this... include("includes/db.php"); include("includes/functions.php"); please...help me..

In reply to by raiin (not verified)

You need to include the external php file e.g. db.php, functions.php into your main php file, making an external php file will make your code more organize..

Hello Sir, Quick question if you can please help me. I want to pass a variable to the shoppingcart.php coming from products.php so that when the customer clicks on "Continue Shopping" it will put the customer back to the products page based on that variable. Basically I call the products page like this for example the $dealID value is 37 "products.php?dealID=37". That part works just fine my problem is when I put the item on the shopping cart when I click on continue shopping I need it to go back to "products.php?dealID=37" but I cant seem to make the shopping cart load the $dealID variable I hope you can help me with this.

when i going to the shoppingcart.php it come out those errors. Please help ASAP..thanks Notice: Undefined index: command in C:\xampp\htdocs\cart\shoppingcart.php on line 5 Notice: Undefined index: command in C:\xampp\htdocs\cart\shoppingcart.php on line 8 Notice: Undefined index: command in C:\xampp\htdocs\cart\shoppingcart.php on line 11 Notice: Undefined variable: msg in C:\xampp\htdocs\cart\shoppingcart.php on line 63

Try to change the error reporting in your php.ini to: error_reporting = E_ALL & ~E_NOTICE Let me know if the error still exist.

Good day. Im blessed to have your free ready code . Thanks a lot it really helps to our project in web :)

How should i link the shopping cart to the email? After checkout it should send a mail with all the items in the cart instaed of going for payment. Please help.

pls tell me how to solve. this ( ! ) Notice: Undefined index: command in C:\wamp\www\shopping cart_rtmh\shoppingcart.php on line 4 how to solve. Notice: Undefined index: cart in C:\wamp\www\shopping cart_rtmh\shoppingcart.php

In reply to by admin

How can I display 'The item is already in the cart' ? Please help...Thank you :)

many many thanks

Notice: Undefined index: command in C:\wamp\www\products.php on line 5 Notice: Undefined index: command in C:\xampp\htdocs\cart\shoppingcart.php on line 5 Notice: Undefined index: command in C:\xampp\htdocs\cart\shoppingcart.php on line 8 Notice: Undefined index: command in C:\xampp\htdocs\cart\shoppingcart.php on line 11 Notice: Undefined variable: msg in C:\xampp\htdocs\cart\shoppingcart.php on line 63 Notice: Undefined index: command in C:\wamp\www\shopping cart_rtmh\shoppingcart.php on line 66

In reply to by Anonymous (not verified)

Same problem here Notice: Undefined index: command in C:\wamp\www\try\products.php on line 5

i want to apply coupon code option any one help me ?

How to put Paypal Checkout, Skrill Checkout, and Bank Wire Transfer which is integrated with this shopping cart?
How to create a php file of it?
Thank you very much.

looks good

Notice: Undefined index: command in C:\wamp\www\products.php on line 5 Notice: Undefined index: command in C:\xampp\htdocs\cart\shoppingcart.php on line 5 Notice: Undefined index: command in C:\xampp\htdocs\cart\shoppingcart.php on line 8 Notice: Undefined index: command in C:\xampp\htdocs\cart\shoppingcart.php on line 11 Notice: Undefined variable: msg in C:\xampp\htdocs\cart\shoppingcart.php on line 63 Notice: Undefined index: command in C:\wamp\www\shopping cart_rtmh\shoppingcart.php on line 66 How do i change this? I tried the "error_reporting = E_ALL & ~E_NOTICE" but hte message still exists.. please help. need this for our final school project.

i downloaded all the files. After importing sql file to mysql. All tables are imported sucessfully but it doesnot contain any fields..what to do.. plz help.

Thanx alot 4 the code, but the problem am having is dat the the image is not display (product image, name and description)what do i do, plz help me.

i have downloaded and done everything, but it mentioned some Apache permission problems

Hi, "Update Crat" not working. I give "There are no items in your shopping cart!". Thank you very much.

sir how to add multiple size in same product in this cart..please help...

How to display 'Item is already in the cart' ?? please show me how to do that. thank u :)

This shopping cart does everything I need, however, it uses MySQL extensions. It would be awesome if this shopping cart was updated to MySQLi. Thank you for posting it.

0){ $pid=$_REQUEST['productid']; //-- original code //echo $_REQUEST['productid']; addtocart($pid,1); header("location:shoppingcart.php"); exit(); } ?> Notice: Undefined index: command in C:\wamp64\www\WSMshop\products.php on line 5 Promised!, i tried my best to fix this but i cant T_T. someone can lend a hand. i already in to the link that admin tells. but i got nothing, Sorry for being not knowledgble of this, but i want to learn.

Add new comment