Simple Ecommerce PHP Shopping Cart Application

Today, We want to share with you Simple Ecommerce PHP Shopping Cart Example.
In this post we will show you simple shopping cart php code, hear for php simple ecommerce script we will give you demo and example for implement.
In this post, we will learn about how to create simple shopping cart in php with an example.

Simple Ecommerce PHP Shopping Cart source

There are the Following The simple About Simple Ecommerce PHP Shopping Cart source Full Information With Example and source code.

PHP Shopping Cart Software Development Overview

As I will cover this Post with live Working example to develop Simple PHP Shopping Cart, so the some major files and Directory File Structure for this example is following below.letโ€™s make a simple OOP PHP shopping cart web Application with MySQL

  • index.php
  • dbcontroller.php
  • style.css
Also Read This ๐Ÿ‘‰   Laravel 6 Auth Redirection Using redirectTo

product-images – Directory

We have buield a dynamic and custom shopping cart application Item gallery by displaying all Items results from MySQL database display table using PHP Example.

Database Product Table for Shopping Cart

Table Name : item_table

  `name` varchar(255) NOT NULL,
  `code` varchar(255) NOT NULL,
  `image` text NOT NULL,
  `price` double(10,2) NOT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `product_code` (`code`)

INSERT INTO `item_table` (`id`, `name`, `code`, `image`, `price`) VALUES
(1, '4D Live Camera', '3DcAM01', 'item-images/live-camera.jpg', 1500.00),
(2, 'External Pen Drive', 'USB02', 'item-images/external-pen-drive.jpg', 800.00),
(3, 'Mobile MI 8', 'wristWear03', 'item-images/mobile-mi-8.jpg', 300.00);

Making Product Gallery for Shopping Cart


This is where I will make a simple HTML form and PHP server side source code for our web application. To make the forms simply all souce code copy and write it into your any text editor Like Notepad++, then save file it as index.php.

Also Read This ๐Ÿ‘‰   Simple PHP Shopping Cart

runQuery("SELECT * FROM item_table WHERE code='" . $_GET["code"] . "'");
			$itemArray = array($codeByItem[0]["code"]=>array('name'=>$codeByItem[0]["name"], 'code'=>$codeByItem[0]["code"], 'product_qty'=>$_POST["product_qty"], 'price'=>$codeByItem[0]["price"]));
			if(!empty($_SESSION["product_cart"])) {
				if(in_array($codeByItem[0]["code"],array_keys($_SESSION["product_cart"]))) {
					foreach($_SESSION["product_cart"] as $k => $v) {
							if($codeByItem[0]["code"] == $k) {
								if(empty($_SESSION["product_cart"][$k]["product_qty"])) {
									$_SESSION["product_cart"][$k]["product_qty"] = 0;
								$_SESSION["product_cart"][$k]["product_qty"] += $_POST["product_qty"];
				} else {
					$_SESSION["product_cart"] = array_merge($_SESSION["product_cart"],$itemArray);
			} else {
				$_SESSION["product_cart"] = $itemArray;
	case "remove":
		if(!empty($_SESSION["product_cart"])) {
			foreach($_SESSION["product_cart"] as $k => $v) {
					if($_GET["code"] == $k)
	case "empty":

<TITLE>Simple PHP with Session Shopping Cart</TITLE>

<div id="cart-live-shopping">
<div class="txt-shopping-header">Shopping Cart <a id="clearButton" href="index.php?action=empty">Empty Cart</a></div>
<table cellpadding="10" cellspacing="1">
<th style="text-align:left"><b>Name</b></th>
<th style="text-align:left"><b>Code</b></th>
<th style="text-align:right"><b>Quantity</b></th>
<th style="text-align:right"><b>Price</b></th>
<th style="text-align:center"><b>Action</b></th>

				<td style="text-align:left;border-bottom:#F5F5F5 1px solid"><b></b></td>
				<td style="text-align:left;border-bottom:#F5F5F5 1px solid"></td>
				<td style="text-align:right;border-bottom:#F5F5F5 1px solid"></td>
				<td style="text-align:right;border-bottom:#F5F5F5 1px solid"></td>
				<td style="text-align:center;border-bottom:#F5F5F5 1px solid"><a href="index.php?action=remove&code=" class="btnRemoveAction">Remove Item</a></td>

<td colspan="5" align="right"><b>Total:</b> </td>

<div id="item-grid-card">
	<div class="txt-shopping-header">Products</div>
	runQuery("SELECT * FROM item_table ORDER BY id ASC");
	if (!empty($arrat_items_all)) { 
		foreach($arrat_items_all as $key=>$value){
		<div class="product-item">
			<form method="post" action="index.php?action=add&code=">
			<div class="product-image"><img src=""></div>
			<div class="item-price-card"></div>

Best online shopping cart for small business


conn = $this->connectDB();
	function connectDB() {
		$conn = mysqli_connect($this->host,$this->user,$this->password,$this->database);
		return $conn;
	function runQuery($query) {
		$result = mysqli_query($this->conn,$query);
		while($row=mysqli_fetch_assoc($result)) {
			$resultset[] = $row;
			return $resultset;
	function numRows($query) {
		$result  = mysqli_query($this->conn,$query);
		$rowcount = mysqli_num_rows($result);
		return $rowcount;	


#cart-live-shopping table{width:100%;background-color:#F5F5F5;}
#cart-live-shopping table td{background-color:#FFFFFF;}

	padding: 10px 10px;
    border-radius: 1px;
    color: #FFFFFF;
    background: #6aadf1;
a.btnRemoveAction{color:#D60202;border:0;padding:1px 10px;font-size:0.9em;}
a.btnRemoveAction:visited{color:#D60202;border:0;padding:1px 10px;font-size:0.9em;}

#clearButton {
	background-color: #3d3d3d;
    border-radius: 4px;
    border: #FFFFFF 1px solid;
    color: #ff0000;
    float: right;
    font-size: 0.8em;
    padding: 1px 10px;
    text-decoration: none;
.insertItemBtn{    background-color: #eb9e4f;
    border: 0;
    padding: 3px 10px;
    color: #3d3d3d;
    margin-left: 1px;
    border-radius: 1px;
#cart-live-shopping {margin-bottom:30px;}
.cart-item {border-bottom: #79b946 1px dotted;padding: 10px;}
#item-grid-card {margin-bottom:30px;}
.product-item {	float:left;	background: #3d3d3d;margin:15px 10px;	padding:5px;border:#CCC 1px solid;border-radius:4px;}
.product-item div{text-align:center;	margin:10px;}
.item-price-card {    
	color: #005dbb;
    font-weight: 600;
.product-image {height:100px;background-color:#FFFFFF;}
.demo-input-box{border-radius:1px;border:#CCC 1px solid;padding:1px 1px;}

Simple PHP Shopping Cart – Output

Simple PHP Shopping Cart
Simple PHP Shopping Cart
Angular 6 CRUD Operations Application Tutorials

Read :

Also Read This ๐Ÿ‘‰   php limit string to 50 characters - 3 Ways to display first 50 characters from text filed


You can also read about AngularJS, ASP.NET, VueJs, PHP.

I hope you get an idea about best online shopping cart for small business.
I would like to have feedback on my blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, donโ€™t forget to share.