Home  >  Article  >  Backend Development  >  PHP shopping cart implementation code (1/2)_PHP tutorial

PHP shopping cart implementation code (1/2)_PHP tutorial

WBOY
WBOYOriginal
2016-07-20 11:08:291532browse

Regarding the shopping cart, this is mostly used in e-commerce. Users select their own products and need to save them, and finally go to the checkout. This is very similar to the supermarket in our actual life, so I will write a simple php shopping cart now. The example code is more detailed and requires only one step. Once processed, it will be OK.

php tutorial shopping cart implementation code

Regarding the shopping cart, this is used more in e-commerce. Users need to save their own products after selecting them, and finally go to the checkout. This is very similar to our actual I live in a supermarket, so I will write a simple php shopping cart example code. It is more detailed and only needs one step. Once it is processed, it will be ok.

Some shopping carts will use php files
main.php to display products
additem.php to add products to the shopping cart
cearcart.php to delete products in the shopping cart
shoppingcart. PHP operation class

User database tutorials include

inventory
create table inventory (
product tinytext not null,
quantity tinytext not null,
id int( 4) default '0' not null auto_increment,
description tinytext not null,
price float(10,2) default '0.00' not null,
category char(1) default '' not null,
key id (id),
primary key (id),
key price (price)
);
insert into inventory values ​​('hard drive','5','1', '80g','5600','1');
insert into inventory values ​​('cpu','12','2','p4-2.4g','6600','1');
insert into inventory values ​​('dvd-rom','7','3','12x','2000','1');
insert into inventory values ​​('motherboardwww.bkjia.com' ,'3','4','asus','5000','2');
insert into inventory values ​​('display card','6','5','64m','4500' ,'1');
insert into inventory values ​​('Burner','4','6','52w','3000','1');

shopping
create table shopping (
session tinytext not null,
product tinytext not null,
quantity tinytext not null,
card tinytext not null,
id int(4) default '0' not null auto_increment,
key id (id),
primary key (id)
);
shopper

create database shopper;
use shopper;
create table shopping (
session tinytext not null,
product tinytext not null,
quantity tinytext not null,
card tinytext not null,
id int(4) default '0' not null auto_increment,
key id (id),
primary key (id)
);
create table inventory (
product tinytext not null,
quantity tinytext not null,
id int( 4) default '0' not null auto_increment,
description tinytext not null,
price float(10,2) default '0.00' not null,
category char(1) default '' not null,
key id (id),
primary key (id),
key price (price)
);
insert into inventory values ​​('hard drive','5','1', '80g','5600','1');
insert into inventory values ​​('cpu','12','2','p4-2.4g','6600','1');
insert into inventory values ​​('dvd-rom','7','3','12x','2000','1');
insert into inventory values ​​('motherboardphp100.com',' 3','4','asus','5000','2');
insert into inventory values ​​('display card','6','5','64m','4500',' 1');
insert into inventory values ​​('Burner','4','6','52w','3000','1');

*/

//main.php displays all items in the shopping cart

include("shoppingcart.php");
$cart = new cart;
$table="shopping ";

/* Query and display information in all inventory tables*/
$query = "select * from inventory";
$invresult = mysql tutorial_query($query);
if (! ($invresult)) {
             echo "Query failed
";
         exit; =0>";
echo "Product numberProduct nameUnit price";
echo "Remaining quantityProduct descriptionAdd to cart";
while($row_inventory = mysql_fetch_object($invresult)) {
echo "id."";
echo "".$row_inventory->product."";
echo "".$row_inventory->price."";
echo "".$row_inventory->quantity. "";
echo "".$row_inventory->description."";
echo "";
}
echo "";
echo "
The products in the shopping cart Quantity∶".$cart->quant_items($table, $session);
echo "

Clear shopping cart";


1 2


http://www.bkjia.com/PHPjc/444892.html

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/444892.htmlTechArticle Regarding the shopping cart, this is commonly used in e-commerce. Users have selected their own products and need to save them. , and finally go to the checkout counter, which is very similar to the supermarket in our actual life, so...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn