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.