In this tutorial, I am demonstrating how to do step by step, a simple tutorial of a shopping cart with PHP 5.6 and MYSQL. This shopping cart application was developed very simple and simple for the learning purpose of all of us who like this language that has saved our lives at any time. One can take this as an easy shopping cart for any website, but this is purely an idea to create a shopping cart website.
Step 1
Let's start by taking a look at the structure of the folder:

๐ Step 1: Project Structure
Here's an overview of the files and folders used in this project:
- styles.css - Custom styles
- app.js - JavaScript functions
- jquery.1.11.2.min.js - jQuery library
- /bootstrap-3.3.5/ - Bootstrap assets
- /images/ - Product images
- create-products.sql - SQL file for table
- cart.php - Cart view and logic
- shopping-cart.php - Product listing and add to cart
๐ ๏ธ Step 2: MySQL Database Connection
Configure your PHP file to connect to your MySQL database like this:
๐ Add Products to Cart
Main File PHP: shopping-cart.php
Given below our full PHP code, copy to use it.
When the user presses the Add to shopping cart button, the product details will be saved in the shopping cart session with SKU and other details. The following code has the add action to the cart and adds the product to the shopping cart session. If we click on the same product several times, the amount will increase.
๐๏ธ Display Products from MySQL
Main File PHP: shopping-cart.phpGiven below our full HTML code, copy to use it.
- This html code lists the products that are added to the database and will be listed with their respective data such as description, price, name to add to the shopping cart by pressing the button. "Add To Cart"
Step 3
File PHP: cart.php- Next, our php code to remove all the products added to the shopping cart that are already in session.
You also have the possibility to empty the cart.
Call and list the existing products in the PHP session
File PHP: cart.php
Given below our full HTML and PHP code, copy to use it.
- This html code lists the products added to the php session that will contain the details of the added products, such as description, price, name, and id.
Confirm for remove item
File JAVASCRIPT: app.jsThe remove () button removes the items added in the cart
I hope you liked this simple shopping cart with php 5.6 and mysql database