SlideShare a Scribd company logo
PHP
Cart
Tables, folder and files
• 3 Tables(Orders, Orders_detail and Products)
• Folder img for store all picture
• Product.php for show all product
• Order.php for receive order
• Show.php for show data in cart
• Delete.php for delete data from cart
• Checkout.php for submit data
• Save_checkout.php for save all data into table
• Clear.php for clear all data from cart
• Cal_p.php for increase order qty in cart
• Cal_m.php for decrease order qty from cart
• Finish_order.php for show message transaction finish
• View_order for preview invoice
• And include.php for connect database
CREATE TABLE Orders
CREATE TABLE `orders` (
`OrderID` int(5) unsigned zerofill NOT NULL auto_increment,
`OrderDate` datetime NOT NULL,
`Name` varchar(100) NOT NULL,
`Address` varchar(500) NOT NULL,
`Tel` varchar(100) NOT NULL,
`Email` varchar(100) NOT NULL,
PRIMARY KEY (`OrderID`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8
AUTO_INCREMENT=3 ;
Insert Data Into Orders
INSERT INTO `orders` VALUES (00001, '2013-08-30 09:59:13',
'Rungsan Suwannahong', '39 RMUTT Thailand', '0211245647',
'rungsansu@gmail.com');
INSERT INTO `orders` VALUES (00002, '2013-08-30 10:15:03',
'Rungsan Suwannahong', '39 RMUTT Thailand', '0211245647',
'rungsansu@gmail.com');
CREATE TABLE ORDERS_DETAIL
CREATE TABLE `orders_detail` (
`DetailID` int(5) NOT NULL auto_increment,
`OrderID` int(5) unsigned zerofill NOT NULL,
`ProductID` int(4) NOT NULL,
`Qty` int(3) NOT NULL,
PRIMARY KEY (`DetailID`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8
AUTO_INCREMENT=5 ;
Insert Data Into Orders_detail
INSERT INTO `orders_detail` VALUES (1, 00001, 4, 1);
INSERT INTO `orders_detail` VALUES (2, 00002, 3, 3);
INSERT INTO `orders_detail` VALUES (3, 00002, 1, 1);
INSERT INTO `orders_detail` VALUES (4, 00002, 4, 1);
CREATE TABLE Product
CREATE TABLE `product` (
`ProductID` int(4) NOT NULL auto_increment,
`ProductName` varchar(100) NOT NULL,
`Price` double NOT NULL,
`Picture` varchar(100) NOT NULL,
PRIMARY KEY (`ProductID`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8
AUTO_INCREMENT=5 ;
Insert Data Into Product
INSERT INTO `product` VALUES (1, 'Product 1', 100, '1.gif');
INSERT INTO `product` VALUES (2, 'Product 2', 200, '2.gif');
INSERT INTO `product` VALUES (3, 'Product 3', 300, '3.gif');
INSERT INTO `product` VALUES (4, 'Product 4', 400, '4.gif');
Product.php
<?
//session_start();
//session_destroy();
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;
charset=utf-8">
</head>
<?
include ("include.php");
$strSQL = "SELECT * FROM product";
$objQuery = mysql_query($strSQL) or die(mysql_error());
?>
<table width="327" border="1">
<tr> <td width="101">Picture</td>
<td width="101">ProductID</td>
<td width="82">ProductName</td>
<td width="79">Price</td>
<td width="37">Cart</td> </tr>
<?
while($objResult = mysql_fetch_array($objQuery))
{ ?>
<tr><td><img src="img/<?=$objResult["Picture"];?>" width=50
></td>
<td><?=$objResult["ProductID"];?></td>
<td><?=$objResult["ProductName"];?></td>
<td><?=$objResult["Price"];?></td>
<td>
<a href="order.php?ProductID=<?=$objResult["ProductID"];?>">
Order</a></td>
</tr>
<?
}
?>
</table>
<br><br><a href="show.php">View Cart</a> | <a
href="clear.php">Clear Cart</a>
<?
mysql_close();
?>
</body>
</html>
Order.php
<?
ob_start();
session_start();
if(!isset($_SESSION["intLine"]))
{
$_SESSION["intLine"] = 0;
$_SESSION["strProductID"][0] = $_GET["ProductID"];
$_SESSION["strQty"][0] = 1;
header("location:show.php");
}
else
{
$key = array_search($_GET["ProductID"],
$_SESSION["strProductID"]);
if((string)$key != "")
{
$_SESSION["strQty"][$key] = $_SESSION["strQty"][$key]+
1;
}
else
{
$_SESSION["intLine"] = $_SESSION["intLine"] + 1;
$intNewLine = $_SESSION["intLine"];
$_SESSION["strProductID"][$intNewLine]=$_GET["ProductID"];
$_SESSION["strQty"][$intNewLine] = 1;
}
header("location:show.php");
}
?>
Show.php
<?
session_start();
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-
8">
</head>
<?
include ("include.php");
?>
<table width="400" border="1">
<tr>
<td width="101">ProductID</td>
<td width="82">ProductName</td>
<td width="82">Price</td>
<td width="79">Qty</td>
<td width="79">Total</td>
<td width="10">Del</td>
<td width="10">Add</td>
<td width="10">minus</td>
</tr>
<?
$Total = 0;
$SumTotal = 0;
for($i=0;$i<=(int)$_SESSION["intLine"];$i++)
{
if($_SESSION["strProductID"][$i] != "")
{
$strSQL = "SELECT * FROM product WHERE ProductID = '".
$_SESSION["strProductID"][$i]."' ";
$objQuery = mysql_query($strSQL) or die(mysql_error());
$objResult = mysql_fetch_array($objQuery);
$Total = $_SESSION["strQty"][$i] * $objResult["Price"];
$SumTotal = $SumTotal + $Total;
?>
<tr>
<td><?=$_SESSION["strProductID"][$i];?></td>
<td><?=$objResult["ProductName"];?></td>
<td><?=$objResult["Price"];?></td>
<td><?=$_SESSION["strQty"][$i]; ?></td>
<td><?=number_format($Total,2);?></td>
<td><a href="delete.php?Line=<?=$i;?>">x</a></td>
<td ><a href= "cal_p.php?ProductID=<?=$objResult["ProductID"];?
>">+</a></td>
<td ><a href= "cal_m.php?ProductID=<?=$objResult["ProductID"];?
>">-</a></td>
</tr>
<?
}
}
?>
</table>
Sum Total <?=number_format($SumTotal,2);?>
<br><br><a href="product.php">Go to Product</a>
<?
if($SumTotal > 0)
{
?>
| <a href="checkout.php">CheckOut</a>
<?
}
?>
<?
mysql_close();
?>
</body>
</html>
Delete.php
<?
ob_start();
session_start();
$Line = $_GET["Line"];
$_SESSION["strProductID"][$Line] = "";
$_SESSION["strQty"][$Line] = "";
header("location:show.php");
?>
Checkout.php
<?
session_start();
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-
8">
</head>
<?
include ("include.php");
?>
<table width="400" border="1">
<tr>
<td width="101">ProductID</td>
<td width="82">ProductName</td>
<td width="82">Price</td>
<td width="79">Qty</td>
<td width="79">Total</td>
</tr>
<?
$Total = 0;
$SumTotal = 0;
for($i=0;$i<=(int)$_SESSION["intLine"];$i++)
{
if($_SESSION["strProductID"][$i] != "")
{
$strSQL = "SELECT * FROM product WHERE ProductID = '".
$_SESSION["strProductID"][$i]."' ";
$objQuery = mysql_query($strSQL) or die(mysql_error());
$objResult = mysql_fetch_array($objQuery);
$Total = $_SESSION["strQty"][$i] * $objResult["Price"];
$SumTotal = $SumTotal + $Total;
?>
<tr>
<td><?=$_SESSION["strProductID"][$i];?></td>
<td><?=$objResult["ProductName"];?></td>
<td><?=$objResult["Price"];?></td>
<td><?=$_SESSION["strQty"][$i];?></td>
<td><?=number_format($Total,2);?></td>
</tr>
<?
}
}
?>
</table>
Sum Total <?=number_format($SumTotal,2);?>
<br><br>
<form name="form1" method="post" action="save_checkout.php">
<table width="304" border="1">
<tr>
<td width="71">Name</td>
<td width="217"><input type="text" name="txtName"></td>
</tr>
<tr>
<td>Address</td>
<td><textarea name="txtAddress"></textarea></td>
</tr>
<tr>
<td>Tel</td>
<td><input type="text" name="txtTel"></td>
</tr>
<tr>
<td>Email</td>
<td><input type="text" name="txtEmail"></td>
</tr>
</table>
<input type="submit" name="Submit" value="Submit">
</form>
<?
mysql_close();
?>
</body>
</html>
Save_checkout.php
<?
session_start();
include ("include.php");
$Total = 0;
$SumTotal = 0;
$strSQL = "
INSERT INTO orders (OrderDate,Name,Address,Tel,Email)
VALUES ('".date("Y-m-d H:i:s")."','".$_POST["txtName"]."','".
$_POST["txtAddress"]."' ,'".$_POST["txtTel"]."','".
$_POST["txtEmail"]."') ";
mysql_query($strSQL) or die(mysql_error());
$strOrderID = mysql_insert_id();
for($i=0;$i<=(int)$_SESSION["intLine"];$i++)
{
if($_SESSION["strProductID"][$i] != "")
{
$strSQL = "INSERT INTO orders_detail(OrderID,ProductID,Qty)
VALUES ('".$strOrderID."','".$_SESSION["strProductID"][$i]."','".
$_SESSION["strQty"][$i]."') ";
mysql_query($strSQL) or die(mysql_error());
}
}
mysql_close();
session_destroy();
header("location:finish_order.php?OrderID=".$strOrderID);
?>
Clear.php
<?
ob_start();
session_start();
session_destroy();
header("location:show.php");
?>
Cal_p.php
<?
ob_start();
session_start();
$key = array_search($_GET["ProductID"], $_SESSION["strProductID"]);
if((string)$key != "")
{ $_SESSION["strQty"][$key] = $_SESSION["strQty"][$key] + 1;}
header("location:show.php");
?>
Cal_m.php
<?
ob_start();
session_start();
$key = array_search($_GET["ProductID"], $_SESSION["strProductID"]);
if((string)$key != "")
{ $_SESSION["strQty"][$key] = $_SESSION["strQty"][$key]-1;}
header("location:show.php");
?>
Finish_order.php
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-
8">
</head>
<body>
Finish Your Order. <br><br>
<a href="view_order.php?OrderID=<?=$_GET["OrderID"];?>">View
Order</a>
</body>
</html>
View_order.php
<html>
<head>
<meta http-equiv="Content-Type"content="text/html; charset=utf-8">
</head>
<?
include ("include.php");
$strSQL = "SELECT * FROM orders WHERE OrderID = '".
$_GET["OrderID"]."' ";
$objQuery = mysql_query($strSQL) or die(mysql_error());
$objResult = mysql_fetch_array($objQuery);
?>
<table width="304" border="1">
<tr>
<td width="71">OrderID</td>
<td width="217">
<?=$objResult["OrderID"];?></td>
</tr>
<tr>
<td width="71">Name</td>
<td width="217">
<?=$objResult["Name"];?></td>
</tr>
<tr>
<td>Address</td>
<td><?=$objResult["Address"];?></td>
</tr>
<tr>
<td>Tel</td>
<td><?=$objResult["Tel"];?></td>
</tr>
<tr>
<td>Email</td>
<td><?=$objResult["Email"];?></td>
</tr>
</table>
<br>
<table width="400" border="1">
<tr>
<td width="101">ProductID</td>
<td width="82">ProductName</td>
<td width="82">Price</td>
<td width="79">Qty</td>
<td width="79">Total</td>
</tr>
<?
$Total = 0;
$SumTotal = 0;
$strSQL2 = "SELECT * FROM orders_detail WHERE OrderID = '".
$_GET["OrderID"]."' ";
$objQuery2 = mysql_query($strSQL2) or die(mysql_error());
while($objResult2 = mysql_fetch_array($objQuery2))
{
$strSQL3 = "SELECT * FROM product WHERE ProductID = '".
$objResult2["ProductID"]."' ";
$objQuery3 = mysql_query($strSQL3) or die(mysql_error());
$objResult3 = mysql_fetch_array($objQuery3);
$Total = $objResult2["Qty"] * $objResult3["Price"];
$SumTotal = $SumTotal + $Total;
?>
<tr>
<td><?=$objResult2["ProductID"];?></td>
<td><?=$objResult3["ProductName"];?></td>
<td><?=$objResult3["Price"];?></td>
<td><?=$objResult2["Qty"];?></td>
<td><?=number_format($Total,2);?></td>
</tr>
<?
}
?>
</table>
Sum Total <?=number_format($SumTotal,2);?>
<?
mysql_close();
?>
<p><a href=product.php>back to main</a>
</body>
</html>
Include.php
<?
mysql_connect("localhost","root","1234");
mysql_select_db("test");
?>

More Related Content

PPT
PHP webboard
PDF
Separation of concerns - DPC12
PPT
Propel sfugmd
PDF
Dig Deeper into WordPress - WD Meetup Cairo
DOC
PDF
php plus mysql
PPTX
CakePHP workshop
PDF
jQuery%20on%20Rails%20Presentation
PHP webboard
Separation of concerns - DPC12
Propel sfugmd
Dig Deeper into WordPress - WD Meetup Cairo
php plus mysql
CakePHP workshop
jQuery%20on%20Rails%20Presentation

What's hot (17)

KEY
Php Code Audits (PHP UK 2010)
DOCX
Sql
PDF
Everything you always wanted to know about forms* *but were afraid to ask
KEY
Introduction à CoffeeScript pour ParisRB
PPTX
DrupalCamp Foz - Novas APIs Drupal 7
PDF
Gareth hayes. non alphanumeric javascript-php and shared fuzzing
PDF
Everything About PowerShell
PDF
R57shell
PDF
PhoneGap: Local Storage
PDF
Solr's Search Relevancy (Understand Solr's query debug)
PDF
Groovy kind of test
PPTX
Open Source Search: An Analysis
PPT
MySQLConf2009: Taking ActiveRecord to the Next Level
PDF
Webmontag Berlin "coffee script"
KEY
Potential Friend Finder
TXT
PDF
PHP tips and tricks
Php Code Audits (PHP UK 2010)
Sql
Everything you always wanted to know about forms* *but were afraid to ask
Introduction à CoffeeScript pour ParisRB
DrupalCamp Foz - Novas APIs Drupal 7
Gareth hayes. non alphanumeric javascript-php and shared fuzzing
Everything About PowerShell
R57shell
PhoneGap: Local Storage
Solr's Search Relevancy (Understand Solr's query debug)
Groovy kind of test
Open Source Search: An Analysis
MySQLConf2009: Taking ActiveRecord to the Next Level
Webmontag Berlin "coffee script"
Potential Friend Finder
PHP tips and tricks
Ad

Viewers also liked (14)

PPTX
Online Shopping Full Project Presentation (20 slides)
DOC
Online shopping report-6 month project
PPTX
Php live project training
PPTX
PHP Training In Ambala! BATRA COMPUTER CENTRE
PDF
UX Final Proposal for Shopping Cart
PPTX
Online shopping site
PPTX
Most Popular Open source Ecommerce shopping carts – Top 20
PDF
How to start ecommerce business in india1.pdf
ODP
Introduction to E-Commerce with Shopping Cart System
PPTX
Online shopping with shopping cart ppt 1
DOC
Project Proposel Documentation
DOC
Problem statement
PPTX
25 php interview questions – codementor
PDF
Online shopping portal: Software Project Plan
Online Shopping Full Project Presentation (20 slides)
Online shopping report-6 month project
Php live project training
PHP Training In Ambala! BATRA COMPUTER CENTRE
UX Final Proposal for Shopping Cart
Online shopping site
Most Popular Open source Ecommerce shopping carts – Top 20
How to start ecommerce business in india1.pdf
Introduction to E-Commerce with Shopping Cart System
Online shopping with shopping cart ppt 1
Project Proposel Documentation
Problem statement
25 php interview questions – codementor
Online shopping portal: Software Project Plan
Ad

Similar to PHP cart (20)

PDF
Gail villanueva add muscle to your wordpress site
PDF
Creating web api and consuming part 2
PPTX
Zero to SOLID
PDF
Contagion的Ruby/Rails投影片
 
PDF
Practical PHP by example Jan Leth-Kjaer
DOC
Ôn tập KTTMDT
PDF
HTML5 New and Improved
PPT
Form demoinplaywithmysql
PDF
Practica n° 7
PDF
The Ring programming language version 1.5.2 book - Part 44 of 181
PPTX
Performante Java Enterprise Applikationen trotz O/R-Mapping
PPTX
DOC
Ex[1].3 php db connectivity
PPT
Testing persistence in PHP with DbUnit
PPTX
Web весна 2013 лекция 6
PDF
Stefan Hochdörfer - The NoSQL Store everyone ignores: PostgreSQL - NoSQL matt...
TXT
Java.script
TXT
Html
Gail villanueva add muscle to your wordpress site
Creating web api and consuming part 2
Zero to SOLID
Contagion的Ruby/Rails投影片
 
Practical PHP by example Jan Leth-Kjaer
Ôn tập KTTMDT
HTML5 New and Improved
Form demoinplaywithmysql
Practica n° 7
The Ring programming language version 1.5.2 book - Part 44 of 181
Performante Java Enterprise Applikationen trotz O/R-Mapping
Ex[1].3 php db connectivity
Testing persistence in PHP with DbUnit
Web весна 2013 лекция 6
Stefan Hochdörfer - The NoSQL Store everyone ignores: PostgreSQL - NoSQL matt...
Java.script
Html

More from tumetr1 (20)

PDF
ตัวอย่างประวัติผู้วิจัย เล่มโปรเจ็ค
PDF
ตัวอย่างภาคผนวก เล่มโปรเจ็ค
PDF
ตัวอย่างบรรณานุกรม เล่มโปรเจ็ค
PDF
ตัวอย่างบทที่1 บทนำ เล่มโปรเจ็ค
PDF
ตัวอย่างสารบัญ เล่มโปรเจ็ค
PDF
ตัวอย่างกิตติกรรมประกาศ เล่มโปรเจ็ค
PDF
ตัวอย่างบทคัดย่อเล่มโปรเจ็ค
PPT
file transfer and access utilities
PPT
retrieving the mail
PPT
connectivity utility
PPT
network hardware
PPT
ระบบเครือข่ายไร้สาย (wireless lan)
PPT
routing
PPT
the transport layer
PPT
ระดับชั้นเน็ตเวิร์ก
PPT
ระดับชั้นดาต้าลิงค์
PPT
สถาปัตยกรรมเครือข่ายคอมพิวเตอร์และบริการ
PPT
การส่งข้อมูลผ่านสายส่งและเทคนิคการส่งข้อมูลผ่านเครือข่าย
PPT
ความรู้พื้นฐานของระบบการสื่อสารข้อมูล
PPT
พัฒนาเศรษฐกิจ
ตัวอย่างประวัติผู้วิจัย เล่มโปรเจ็ค
ตัวอย่างภาคผนวก เล่มโปรเจ็ค
ตัวอย่างบรรณานุกรม เล่มโปรเจ็ค
ตัวอย่างบทที่1 บทนำ เล่มโปรเจ็ค
ตัวอย่างสารบัญ เล่มโปรเจ็ค
ตัวอย่างกิตติกรรมประกาศ เล่มโปรเจ็ค
ตัวอย่างบทคัดย่อเล่มโปรเจ็ค
file transfer and access utilities
retrieving the mail
connectivity utility
network hardware
ระบบเครือข่ายไร้สาย (wireless lan)
routing
the transport layer
ระดับชั้นเน็ตเวิร์ก
ระดับชั้นดาต้าลิงค์
สถาปัตยกรรมเครือข่ายคอมพิวเตอร์และบริการ
การส่งข้อมูลผ่านสายส่งและเทคนิคการส่งข้อมูลผ่านเครือข่าย
ความรู้พื้นฐานของระบบการสื่อสารข้อมูล
พัฒนาเศรษฐกิจ

Recently uploaded (20)

PDF
01-Introduction-to-Information-Management.pdf
PPTX
human mycosis Human fungal infections are called human mycosis..pptx
PPTX
GDM (1) (1).pptx small presentation for students
PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
PDF
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
PDF
Pre independence Education in Inndia.pdf
PDF
Classroom Observation Tools for Teachers
PDF
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
PDF
Insiders guide to clinical Medicine.pdf
PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PDF
O5-L3 Freight Transport Ops (International) V1.pdf
PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PPTX
PPH.pptx obstetrics and gynecology in nursing
PDF
Anesthesia in Laparoscopic Surgery in India
PDF
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
PDF
Complications of Minimal Access Surgery at WLH
PDF
Sports Quiz easy sports quiz sports quiz
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PDF
Microbial disease of the cardiovascular and lymphatic systems
PDF
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
01-Introduction-to-Information-Management.pdf
human mycosis Human fungal infections are called human mycosis..pptx
GDM (1) (1).pptx small presentation for students
2.FourierTransform-ShortQuestionswithAnswers.pdf
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
Pre independence Education in Inndia.pdf
Classroom Observation Tools for Teachers
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
Insiders guide to clinical Medicine.pdf
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
O5-L3 Freight Transport Ops (International) V1.pdf
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PPH.pptx obstetrics and gynecology in nursing
Anesthesia in Laparoscopic Surgery in India
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
Complications of Minimal Access Surgery at WLH
Sports Quiz easy sports quiz sports quiz
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
Microbial disease of the cardiovascular and lymphatic systems
Chapter 2 Heredity, Prenatal Development, and Birth.pdf

PHP cart