Add shopping items with PHP

Source: Internet
Author: User
Tags explode

1<?PHP2 Session_Start(); 3 Header("content-type:text/html; Charset=utf-8 ");//set file encoding format4 require("system/system.inc.php");//include configuration Files5 /**6 * 1 indicates successful addition7 * 2 indicates that the user is not logged in8 * 3 indicates that the product has been added9 * 4 Indicates an error occurred while addingTen * 5 means no product added One */ A $reback= ' 0 '; - if(Empty($_session[' member '])) {//determine if the user is logged in -     $reback= ' 2 ';//No, return 2 . the}Else{ -     $key=$_get[' Key '];//determine if the user has added a product -     if($key= = ") {//determine if the user has added a product, if it is empty, it means there is no product. -         $reback= ' 5 ';//return value +}Else{     -         $boo=false;//define if the product has not been added +         $sqls= "Select id,shopping from tb_user where name = '".$_session[' member ']. "'";  A         $shopcont=$admindb->execsql ($sqls,$conn); at         if(!Empty($shopcont[0] [' Shopping '])) {//Shopping is a three-dimensional array, with empty to determine whether the product is empty -             $arr=Explode(‘@‘,$shopcont[0] [' shopping ']);//The @ Split array is the value of each item -             foreach($arr  as $value){//foreach extracts the value of each array -                 $arrtmp=Explode(‘,‘,$value);//using explode to divide the information of a product's body -                 if($key==$arrtmp[0]) {//if the added item equals the added item -                     $reback= ' 3 ';//then the return value means that you have added in                     $boo=true;  -                      Break; to                 } +             } -             if($boo==false){//method One Add Item the                 $shopcont[0] [' shopping ']. = ' @ '.$key. ', 1 ';  *                 $update= "Update tb_user set shopping= '".$shopcont[0] [' Shopping ']. "' WHERE name = ' ".$_session[' member ']. "'"; $                 $shop=$admindb->execsql ($update,$conn);Panax Notoginseng                 if($shop){ -                     $reback= 1; the}Else{ +                     $reback= ' 4 '; A                 } the             } +}Else{ -             $arrtmp=$key. ", 1";//method Two Add a product $             $updates= "Update tb_user set shopping= '".$arrtmp. "' WHERE name = '".$_session[' member ']. "'"; $             $result=$admindb->execsql ($updates,$conn); -             if($result){ -                 $reback= 1; the}Else{ -                 $reback= ' 4 ';Wuyi             } the         } -     } Wu } - Echo $reback; About?>

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.