The shopping cart function realizes through the Php+mysql+jquery+ajax, realizes the shopping cart function

Source: Internet
Author: User
Tags php foreach

Database structure:


Prepare 3 files:

1.cart.php//Front-end display file

2.cart_ajax.php//AJAX processing data

3.config.php//Database configuration

First, cart.php

<pre name= "code" class= "HTML" ><?phpinclude ' config.php '; $sql = "SELECT * from cart"; $result = mysql_query ($sql) ; $row = Array (); while ($rows = Mysql_fetch_array ($result, Mysql_assoc)) {$row [] = $rows;} Print_r ($row);? ><! DOCTYPE html>

Second, config.php

<?php/** *email:scenewood@163.com *name: Zheng Small Wood * * $server = ' localhost '; $data = ' shopping '; mysql_connect ($server, ' Root ', ' root '); Mysql_set_charset (' UTF8 '); mysql_select_db ($data);

Third, cart_ajax.php

<?php/** *email:scenewood@163.com *name: Zheng Xiao mu */include ' config.php ';//Accept cart.php data if ($_post) {    $id = $_post[' Id '];    $num = $_post[' num '];    $retureInfo = Array (        ' status ' = = 0,        ' info ' = ' Modify product quantity failed '    );    $sql = "UPDATE ' cart ' SET num= ' {$num} ' WHERE ' id ' ={$id}";    mysql_query ($sql);    $row = Mysql_affected_rows ();    if ($row = = 1) {        $retureInfo [' status '] = 1;        $retureInfo [' info '] = ' Modify the number of items successfully ';    }    echo Json_encode ($retureInfo);}

This article explains the shopping cart function realizes through the Php+mysql+jquery+ajax, realizes the shopping cart function, more related content please concern the PHP Chinese net.

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.