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?>