Home >
Backend Development >
PHP Tutorial >
PHP basic example: product information management system v1.1, information management system v1.1_PHP tutorial
PHP basic example: product information management system v1.1, information management system v1.1_PHP tutorial
WBOY
Release: 2016-07-13 09:53:04
Original
1440 people have browsed it
PHP basic example: product information management system v1.1, information management system v1.1
Achieve the goal: use php and mysql to write a product information management system with Shopping cart function
1. Create database and tables
1. Create database and tables: demodb
2. Create a table: goods
Fields: product number, product name, product type, product picture, unit price, product description, inventory, adding time
2. Create the php file and write the code (the following is the php file to be created and its purpose)
add.php Product addition page
edit.php Product information editing form page
Index.php Product information browsing page
action.php Perform operations such as adding, modifying and deleting product information
dbconfig.php public configuration file, database connection configuration information
Menu.php Website public navigation bar
Uploads/ Storage directory for uploaded images
Function.php public function library file: uploading of image information, scaling and other processing functions
AddCart.php operation of adding shopping cart information (putting purchase information into SESSION)
MyCart.php implements the browsing operation of shopping cart information, and implements the statistics of product information (subtotal and total price)
ClearCart.php implements the operation of deleting a single product or clearing the shopping cart of shopping cart information
UpdateCart.php Modify the number of items in the shopping cart to prevent too small constraints
Illustration of the relationship between each php file:
The following is the code of each php file. Friends who need it can directly copy each code and put it in the same directory. You must also create an uplaods folder in the same directory to store uploaded images
1 2 3Product Information Management 4 5 6
7 include("menu.php");//Import navigation bar ?>
8
11 include("menu.php");//Import navigation bar ?>
12
Add items to cart
1314php
15//Read the information to be purchased from the database and add it to the shopping cart
16 //1. Import configuration file 17require("dbconfig.php");
18//2. Connect to the database and select the database 19$link = @mysql_connect(HOST,USER,PASS) or die("Database connection failed");
20mysql_select_db(DBNAME,$link);
21//3. Perform product information query (obtain the information to be purchased) 22$sql="select * from goods where id={$_GET['id']}";
23$result = mysql_query($sql,$link);
2425//4. Determine whether the information you want to purchase is not found, and if so, read and retrieve the information you want to purchase 26if(empty($result) || mysql_num_rows($result )==0)
27 {
28die("No information found to buy!");
29 }else30 {
31$shop = mysql_fetch_assoc($result);
32 }
33$shop["num"]=1;//Add a quantity field
34 //5. Put it in the shopping cart (if the quantity of existing products is accumulated) 35if(isset($_SESSION["shoplist"]{$shop['id']}))
36 {
37//If the existing quantity increases by 138$_SESSION["shoplist"][$shop['id']]["num"] ;
39 }else40 {
41//If it does not exist, add it to the shopping cart as a newly purchased item42$_SESSION["shoplist"][$shop['id']]=$shop;
43 }4445 ?>
4647
5253myCart.php 1php
2 3//Delete the information in the shopping cart session 4session_start();//Start session
5 6 //Determine whether to delete an item or clear the shopping cart 7if($_GET['id'])
8 {
9//Delete only one product10unset($_SESSION['shoplist'][$_GET['id']]);
11 }else12 {
13//Clear the products in the session14unset($_SESSION["shoplist"]);
15 }
161718//Jump to the shopping cart interface19header("Location:myCart.php");
20 ?>
clearCart.php 1php
2session_start();//Start session
3 //Modify the information in the shopping cart
4 5 //Get the information to be modified 6 7$id = $_GET['id'];
8$num = $_GET['num'];
910//Modify product information11$_SESSION["shoplist"][$id]["num"] =$num;
1213//Prevent the quantity of products from being too small14if($_SESSION["shoplist"][$id]["num"]<1)
15 {
16$_SESSION["shoplist"][$id]["num"]=1;
17 }
18//Jump back to my shopping cart interface19header("Location:myCart.php");
2021 ?>
updateCart.php
The following is a screenshot of index.php:
myCart.php screenshot:
Finally, I would like to say: Hahahahahahahahahahahahahahaha! ! ! !
http://www.bkjia.com/PHPjc/1005210.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1005210.htmlTechArticlePHP basic example: commodity information management system v1.1, information management system v1.1 to achieve the goal: use php and Write a product information management system in mysql with a shopping cart function 1. Create data...
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