用PHP添加購物商品

來源:互聯網
上載者:User

標籤:style   blog   color   檔案   io   art   

 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‘;              //沒有就返回215 }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 ?>

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.