How to Build Shopping Cart w/ Checkout in PHP

Submitted by: 
Language: 
Visitors have accessed this post 143741 times.

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?

hi
i suggest create a directory in your server first and transfer files second...

please solve my problem after using the How to Build Shopping Cart w / Checkout in PHP is, after I tried to check out why the data from a shopping cart in the shopping cart data is still there? thank... please replay by email [email protected]

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 :(

I admire this programer to make shopping cart with ckeckout system.

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..

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.

I tried to change to ~E_DEPRECATED & ~E_STRICT but nothings happened. there are still errors. Help pleaseeee

It should be error_reporting = E_ALL & ~E_NOTICE and not ~E_DEPRECATED & ~E_STRICT

Please tell me in which file can i include this code??

anwar

which file shall i make these changes to??

anwar

thank you very much :)

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

can you please share that code c'ze i'm having same error that you had!

Thanks!

anwar

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.

plz help me how to show that specfic image to cart when i pressed add to cart

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

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

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

I have already replied this kind of error many times. Click this link http://www.sourcecodester.com/comment/31051#comment-31051

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.

need to increase items of the same category from 1 to say 3 and updating- calculating the same.

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.

Hey frnds. if any one have a easy and efficient that is proper worked. So plzz send me at [email protected] i need for my website. plzz help me !

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.

<?php
include("includes/db.php");
include("includes/functions.php");

if($_REQUEST['command']=='add' && $_REQUEST['productid']>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

Filtered HTML

  • Web page addresses and e-mail addresses turn into links automatically.
  • You may insert videos with [video:URL]
  • Allowed HTML tags: <a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd> <table> <tr> <td> <th> <img> <h1> <h2> <h3> <iframe> [video]
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>, <asp>, <c>, <cpp>, <csharp>, <css>, <html4strict>, <java>, <javascript>, <mysql>, <php>, <python>, <sql>, <vb>, <vbnet>. The supported tag styles are: <foo>, [foo].
  • Lines and paragraphs break automatically.

Plain text

  • No HTML tags allowed.
  • Lines and paragraphs break automatically.
CAPTCHA
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.