PHP头条
热点:

用PHP添加购物商品,PHP添加购物商品


 1 <?php
 2 session_start(); 
 3 header ( "Content-type: text/html; charset=UTF-8" );                         //设置文件编码格式
 4 require("system/system.inc.php");                          //包含配置文件
 5 /**
 6     *  1表示添加成功
 7     *  2表示用户没有登录
 8     *  3表示商品已添加过
 9     *  4表示添加时出现错误
10     *  5表示没有商品添加
11 */
12 $reback = '0';
13 if(empty($_SESSION['member'])){ //判断用户有没有登录
14     $reback = '2';              //没有就返回2
15 }else{
16     $key = $_GET['key'];         //判断用户有没有添加商品
17     if($key == ''){              //判断用户有没有添加商品,如果为空就表示没有商品喽
18         $reback = '5';           //返回值
19     }else{    
20         $boo = false;             //定义商品有没有被添加
21         $sqls = "select id,shopping from tb_user where name = '".$_SESSION['member']."'"; 
22         $shopcont = $admindb->ExecSQL($sqls,$conn);
23         if(!empty($shopcont[0]['shopping'])){  //shopping为三维数组,用empty判断商品是否为空
24             $arr = explode('@',$shopcont[0]['shopping']);//@分割数组也就是每个商品的值
25             foreach($arr as $value){ //foreach取出每个数组的值
26                 $arrtmp = explode(',',$value);            //用explode分割得出商品的俱体信息
27                 if($key == $arrtmp[0]){                 //如果添加的商品等于已添加的商品
28                     $reback = '3';                      //那么返回值就表示已添加
29                     $boo = true;                         
30                     break;
31                 }
32             }
33             if($boo == false){              //方法一添加商品
34                 $shopcont[0]['shopping'] .= '@'.$key.',1'; 
35                 $update = "update tb_user set shopping='".$shopcont[0]['shopping']."' where name = '".$_SESSION['member']."'";
36                 $shop = $admindb->ExecSQL($update,$conn);
37                 if($shop){
38                     $reback = 1;
39                 }else{
40                     $reback = '4';
41                 }
42             }
43         }else{
44             $arrtmp = $key.",1";          //方法二添加商品
45             $updates = "update tb_user set shopping='".$arrtmp."' where name = '".$_SESSION['member']."'";
46             $result = $admindb->ExecSQL($updates,$conn);
47             if($result){
48                 $reback = 1;
49             }else{
50                 $reback = '4';
51             }
52         }
53     }
54 }
55 echo $reback;
56 ?>

PHP 购物网站 怎在后台添加商品并在前台显示?

可以用PHP的网店程序,也可以自己写!

如果用网店程序的话,详看一下相关后台的说明。其实很简单的。

如果自己有能力写的话 完全可以自己写,EASY。
 

怎防止刷新浏览器购物车中商品数量自动加1,php做的购物网站

用Ajax做异步提交,都是这么做的。。。addtocart();
 

www.phpzy.comtrue/php/12369.htmlTechArticle用PHP添加购物商品,PHP添加购物商品 1 ? php 2 session_start (); 3 header ( "Content-type: text/html; charset=UTF-8" ); // 设置文件编码格式 4 require ("system/system.inc.php"); // 包含配置文件 5 /* * 6 * 1表示添加...

相关文章

    暂无相关文章
相关频道:

PHP之友评论

今天推荐