This article describes how to add a product to the shopping cart in php, which has some reference value, if you are interested, you can refer to this article for details about the php shopping cart function, which has some reference value. if you are interested, you can refer to it.
Today, I am practicing shopping cart and submitting orders. I am a little dizzy. By the way, I also sorted out that this shopping cart is relatively simple and used for temporary storage and is not stored in the database, shopping cart is almost familiar to people who love online shopping. before writing a shopping cart, we must first think about it. we need to call out a table from the database first, here I use the fruit table, followed by the login table, and I use the login table to call the user name and password, when everything is ready, you have to consider the following three situations:
First case:Nothing in the shopping cart
Case 2:This product already exists in the shopping cart. if you add this product again, the quantity must be greater than 1.
Case 3:There is a product in the shopping cart, but there is no such product
Used database tables:
The following is the logon page code:
After logging on to the page, you need to go to the processing page and call up the user name and password from the database:
Query ($ SQL); if ($ arr [0] [0] ==$ pwd &&! Empty ($ pwd) // Determine whether the entered password is the same as the obtained password, and the password cannot be blank {$ _ SESSION ["uid"] = $ uid; header ("location: main. php ");} else {echo" logon failed ";}
Logon page:
Next we will go to the home page, and call out all the fruit information from the database. then we will implement the function of adding to the shopping cart.
Big Apple Shopping Network
{$ Zhonglei}{$ Sum}
Code |
Fruit name |
Fruit price |
Origin |
Shelf |
Inventory |
|
Query ($ SQL); foreach ($ arr as $ v) {echo"
{$ V [0]} | // Call out the required content from the database
{$ V [1]} |
{$ V [2]} |
{$ V [3]} |
{$ V [4]} |
{$ V [5]} |
Purchase | // The purchase here is equivalent to the function of adding a shopping cart.
";}?> Query ($ sql1); foreach ($ danjia as $ n) {$ sum = $ sum + $ n [0] * $ k [1] ;}} echo "shopping cart hasType of goods, the total price isYuan ";?>
View shopping cart browse product View Account
Home page:
The most important thing is to add a shopping cart page.
In this way, the shopping cart page is displayed. the code of the shopping cart page is as follows:
The shopping cart contains the following items:
Product Name |
Unit Price |
Quantity purchased |
|
Query ($ SQL, 1); foreach ($ att as $ n) {echo"
{$ N [1]} |
{$ N [2]} |
{$ V [1]} |
Delete |
";}}?>
View shopping cart browse product View Account
14 15
In this way, the shopping cart page is displayed:
This is just a simple addition to the shopping cart, but there are still many incomplete links in the middle. for example, after adding the shopping cart to the shopping cart, operations such as reducing the number of products in the database and deleting the products in the shopping cart have not been done yet, make up later.
The above is a detailed description of the graphic code for php to add the product to the shopping cart function. For more information, see other related articles in the first PHP community!