Add shopping items with PHP, PHP add shopping items _php Tutorial

Source: Internet
Author: User
Tags php online

Add a shopping item in PHP, add a shopping item to PHP


 1 
    php 
 2 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?>

How does the PHP shopping site add items in the background and display them in the foreground?

You can use the PHP online program, you can also write your own!

If you use the shop program, look at the relevant background instructions. Actually, it's very simple.

If you have the ability to write, you can write your own, easy.

How to prevent refresh browser shopping cart in the number of items automatically add 1,php do shopping site

Asynchronous commit with Ajax, it's all done ... AddToCart ();

http://www.bkjia.com/PHPjc/838914.html www.bkjia.com true http://www.bkjia.com/PHPjc/838914.html techarticle Add a shopping item in PHP, add a shopping item to PHP 1 PHP 2 session_start (); 3 header ("content-type:text/html; Charset=utf-8 "); Set file Encoding format 4 require ("system/s ...

  • Related Article

    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.