Home arrow MySQL arrow Building A Persistent Shopping Cart With PHP and MySQL
MYSQL

Building A Persistent Shopping Cart With PHP and MySQL


If you take a look around any PHP resource site, you'll notice an exorbitant amount of shopping cart scripts. The fact of the matter is that shopping cart scripts aren't hard to develop. In this article Mitchell shows us how to build a simple shopping cart that persists across multiple browser sessions. He uses PHP, MySQL, and JavaScript to implement each part of the shopping cart.

Author Info:
By: Mitchell Harper
Rating: 4 stars4 stars4 stars4 stars4 stars / 214
May 18, 2002
TABLE OF CONTENTS:
  1. · Building A Persistent Shopping Cart With PHP and MySQL
  2. · Creating the database
  3. · Displaying the items
  4. · The cart.php script
  5. · The ShowCart function
  6. · Conclusion

print this article
SEARCH DEVARTICLES

Building A Persistent Shopping Cart With PHP and MySQL
(Page 1 of 6 )

If you take a look around any PHP resource site, you'll notice an exorbitant amount of shopping cart scripts. The fact of the matter is that shopping cart scripts aren't hard to develop. A shopping cart script simply needs to work with some sort of storage device to store a list of items and how many of those items your visitor has chosen to add to their cart.

Typically we would use a database (such as MySQL) to store a list of products and their prices. We would then use PHP's session handling capabilities to store a list of products and amounts relating to each particular visitor, based on their session details.

This is a good way to do things, but what happens if you want to persist the details of that users cart across multiple sessions? I.e., if they close the web browser and come back the next day. You could setup a login system where users register and confirm their details by replying to a confirmation email, but more often you'd like to keep your checkout as simple as possible by just letting the user enter their address and payment method and continue right through to the confirmation page.

By persisting a cookie on the users machine and by using some PHP, we can make a simple shopping cart that will store the details of what the user wants to buy. These details will remain intact, even after the user closes the browser.

So, in this article we will build a simple persistent shopping cart. We will be using PHP and MySQL to do so, so you should have intermediate knowledge of both PHP and MySQL. You will be able to take the code that we will use and adapt it to create your own simple shopping cart for your web site.
blog comments powered by Disqus
MYSQL ARTICLES

- MySQL and BLOBs
- Two Lessons in ASP and MySQL
- Lord Of The Strings Part 2
- Lord Of The Strings Part 1
- Importing Data into MySQL with Navicat
- Building a Sustainable Web Site
- Creating An Online Photo Album with PHP and ...
- Creating An Online Photo Album with PHP and ...
- PhpED 3.2 More Features Than You Can Poke ...
- Creating An Online Photo Album with PHP and ...
- Creating An Online Photo Album with PHP and ...
- Security and Sessions in PHP
- Setup Your Personal Reminder System Using PHP
- Create a IP-Country Database Using PERL and ...
- Developing a Dynamic Document Search in PHP ...

Watch our Tech Videos 
Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 

Developer Shed Affiliates

 




© 2003-2017 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials