


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
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:
Okay, here is the code part:
The first is the table creation statement:

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

Publish product information
9 53
View product information"; 53 54 break; 55 case "del": //delete 56 //Get the id number to be deleted and assemble the deletion sql, execute 57 $sql = "delete from goods where id={$_GET['id']}"; 58 59 mysql_query($sql,$link); 60 //Perform image deletion 61 if(mysql_affected_rows($link)>0) 62 { 63 @unlink("./uploads/".$_GET['picname']); 64 @unlink("./uploads/s_".$_GET['picname']); 65 } 66 //Jump to the browsing interface 67 header("Location:index.php"); 68 break; 69 70 case "update": //Modify 71 //1. Get the information to be modified 72 $name = $_POST["name"]; 73 $typeid = $_POST["typeid"]; 74 $price = $_POST["price"]; 75 $total = $_POST["total"]; 76 $note = $_POST["note"]; 77 $id = $_POST['id']; 78 $pic = $_POST['oldpic']; 79 //2. Data verification 80 if(empty($name)) 81 { 82 die("The product name must have a value"); 83 } 84 //3. Determine whether there is an image uploaded 85 if($_FILES['pic']['error']!=4) 86 { 87 //Execute upload 88 $upinfo = uploadFile("pic","./uploads/"); 89 if($upinfo["error"]===false) 90 { 91 die("Picture information upload failed:".$upinfo["info"]); 92 }else 93 { 94 //Upload successful 95 $pic = $upinfo["info"];//Get the name of the successfully uploaded picture 96 //4. Execute scaling when uploading images 97 imageUpdateSize('./uploads/'.$pic,50,50); 98 } 99 } 100 101 102 //5. Execute modifications 103 $sql = "update goods set name='{$name}',typeid={$typeid},price= {$price},total={$total},note='{$note}',pic='{$pic}' where id={$id}"; 104 mysql_query($sql,$link); 105 //6. Determine whether the modification is successful 106 if(mysql_affected_rows($link)>0) 107 { 108 if($_FILES['pic']['error']!=4) 109 { 110 //If there are pictures uploaded, delete the old pictures 111 @unlink("./uploads/".$_POST['oldpic']); 112 @unlink("./uploads/s_".$_POST['oldpic']); 113 } 114 echo "Modification successful" ; 115 }else 116 { 117 echo "Modification failed".mysql_error(); 118 } 119 echo "
View product information"; 120 break; 121 default: 122 echo "Error";break; 123 124 }125 //4. Close the database 126 mysql_close($link); action.php


Browse product information
9
10
Item number | 13Product Name | 14Product pictures | 15Unit price | 16Inventory | 17Add time | 18Operation | 19
---|---|---|---|---|---|---|
{$row["id"]} | "; 36 echo "{$row["name"]} | "; 37 echo "{$row["price"]} | "; 39 echo "{$row["total"]} | "; 40 echo "".date("Y-m-d H:i:s",$row['addtime'])." | "; 41 echo "42 $row['pic']}'>删除 43 修改 44 放入购物车 45 46 | "; 47 echo "

编辑商品信息
28 81

Product information management--shopping cart
2 Browse products| 3 Add product| 4 5 My Shopping Cart| 6 Clear shopping cart 7 8 9menu.php

Add items to cart
13
14 php
15 //Read the information to be purchased from the database and add it to the shopping cart
16 //1. Import configuration file
17 require("dbconfig.php");
18 //2. Connect to the database and select the database
19 $link = @mysql_connect(HOST,USER,PASS) or die("Database connection failed");
20 mysql_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);
24
25 //4. Determine whether the information you want to purchase is not found, and if so, read and retrieve the information you want to purchase
26 if(empty($result) || mysql_num_rows($result )==0)
27 {
28 die("No information found to buy!");
29 }else
30 {
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)
35 if(isset($_SESSION["shoplist"]{$shop['id']}))
36 {
37 //If the existing quantity increases by 1
38 $_SESSION["shoplist"][$shop['id']]["num"] ;
39 }else
40 {
41 //If it does not exist, add it to the shopping cart as a newly purchased item
42 $_SESSION["shoplist"][$shop['id']]=$shop;
43 }44
45 ?>
46
47

View my shopping cart
13
Product ID number | 16Product Name | 17Product pictures | 18Unit price | 19Quantity | 20Subtotal | 21Operation | 22
---|---|---|---|---|---|---|
{$v['id']} | "; 30 echo "{$v['name']} | "; 31 echo "{$v['price']} | "; 33 echo "34 35 {$v['num']} 36 37 | "; 38 echo "".($v["price"]*$v['num '])." | "; 39 echo "Delete | "; 40 echo "|
Total amount: | 47echo $sum; ?> | 4849 |



The following is a screenshot of index.php:
myCart.php screenshot:
Finally, I would like to say: Hahahahahahahahahahahahahahaha! ! ! !

What’s still popular is the ease of use, flexibility and a strong ecosystem. 1) Ease of use and simple syntax make it the first choice for beginners. 2) Closely integrated with web development, excellent interaction with HTTP requests and database. 3) The huge ecosystem provides a wealth of tools and libraries. 4) Active community and open source nature adapts them to new needs and technology trends.

PHP and Python are both high-level programming languages that are widely used in web development, data processing and automation tasks. 1.PHP is often used to build dynamic websites and content management systems, while Python is often used to build web frameworks and data science. 2.PHP uses echo to output content, Python uses print. 3. Both support object-oriented programming, but the syntax and keywords are different. 4. PHP supports weak type conversion, while Python is more stringent. 5. PHP performance optimization includes using OPcache and asynchronous programming, while Python uses cProfile and asynchronous programming.

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

PHP originated in 1994 and was developed by RasmusLerdorf. It was originally used to track website visitors and gradually evolved into a server-side scripting language and was widely used in web development. Python was developed by Guidovan Rossum in the late 1980s and was first released in 1991. It emphasizes code readability and simplicity, and is suitable for scientific computing, data analysis and other fields.

PHP is suitable for web development and rapid prototyping, and Python is suitable for data science and machine learning. 1.PHP is used for dynamic web development, with simple syntax and suitable for rapid development. 2. Python has concise syntax, is suitable for multiple fields, and has a strong library ecosystem.

PHP remains important in the modernization process because it supports a large number of websites and applications and adapts to development needs through frameworks. 1.PHP7 improves performance and introduces new features. 2. Modern frameworks such as Laravel, Symfony and CodeIgniter simplify development and improve code quality. 3. Performance optimization and best practices further improve application efficiency.

PHPhassignificantlyimpactedwebdevelopmentandextendsbeyondit.1)ItpowersmajorplatformslikeWordPressandexcelsindatabaseinteractions.2)PHP'sadaptabilityallowsittoscaleforlargeapplicationsusingframeworkslikeLaravel.3)Beyondweb,PHPisusedincommand-linescrip

PHP type prompts to improve code quality and readability. 1) Scalar type tips: Since PHP7.0, basic data types are allowed to be specified in function parameters, such as int, float, etc. 2) Return type prompt: Ensure the consistency of the function return value type. 3) Union type prompt: Since PHP8.0, multiple types are allowed to be specified in function parameters or return values. 4) Nullable type prompt: Allows to include null values and handle functions that may return null values.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Dreamweaver CS6
Visual web development tools