Php graphic code for adding a product to a shopping cart

Source: Internet
Author: User
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}
 
  Query ($ SQL); foreach ($ arr as $ v) {echo" 
   // Call out the required content from the database 
    // 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 ";?> 
  
Code Fruit name Fruit price Origin Shelf Inventory
{$ V [0]}{$ V [1]} {$ V [2]} {$ V [3]} {$ V [4]} {$ V [5]} Purchase

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:
  
   Query ($ SQL, 1); foreach ($ att as $ n) {echo" 
    ";}}?> 
   
Product Name Unit Price Quantity purchased
{$ 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!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.