PHP shopping cart complete implementation code_PHP tutorial

WBOY
Release: 2016-07-13 10:29:01
Original
1287 people have browsed it

1. Product display page

Copy code The code is as follows:















View information】










if(trim($info[tupian]==""))
{
echo "No pictures yet";
}
else
{
?>
}
?>
< ;/td>
< /td>
[Market price:]
[Member price:
Add to cart]
[Remaining quantity:
]-$info[cishu])>0)
{
echo ($info[shuliang]-$info[cishu]);
}
else
echo {
echo "Sold out";
}
?>】

}
?>  


2. File addgouwuche.php



Copy code The code is as follows:
session_start();
include("conn.php");

if($_SESSION[username]=="")
{
echo "<script>alert( 'Please log in first before shopping!');history.back();</script>";
exit;
}
$id=strval($_GET[id]);
$sql=mysql_query("select * from shangpin where id='".$id."'",$conn);
$info=mysql_fetch_array($sql);
if($info[shuliang]< ;=0)
{
echo "<script>alert('This item has been sold out!');history.back();</script>";
exit;
}
$array=explode("@",$_SESSION[producelist]);
for($i=0;$i {
if($array[$i]==$id)
{
echo "<script>alert('This item is already in your shopping cart!');history.back();&lt ;/script>";<br> exit;<br> }<br> }<br> $_SESSION[producelist]=$_SESSION[producelist].$id."@";<br> $_SESSION[quatity]= $_SESSION[quatity]."1@";<br><br> header("location:gouwu1.php");<br>?><br><br> </div> 3. File gouwu1.php <p><br><br></p> <div class="codetitle"> <span style="CURSOR: pointer" onclick="doCopy('code83238')">Copy code <u></u> The code is as follows: </span><div class="code" id="code83238"> <br><?php<br> session_start();<br> if($_SESSION[username]=="")<br>  {<br>    echo "<script>alert('请先登录,后购物!');history.back();</script>";
 exit;
  }  
?>
include("top.php");
?>

 
   
   
   


 
   
 
     
       
     
   
 
    
     
       
         
 
         
         
 


的购物车

   session_start();
     session_register("total");
     if($_GET[qk]=="yes")
     {
        $_SESSION[producelist]="";
     $_SESSION[quatity]=""; 
     }
      $arraygwc=explode("@",$_SESSION[producelist]);
      $s=0;
      for($i=0;$i      {
          $s+=intval($arraygwc[$i]);
      }
     if($s==0 )
       {
       echo "
";
   echo" ";
   echo"";
    }
     else
      { 
   ?>

 
 
 
 
 
 
 

/**
* 购物车 商品数量管理
* Edit www.jbxue.com
*/
$total=0;
$array=explode("@",$_SESSION[producelist]);
$arrayquatity=explode("@",$_SESSION[quatity]);

while(list($name,$value)=each($_POST))
{
for($i=0;$i {
if(($array[$i])==$name)
{
$arrayquatity[$i]=$value;
}
}
}

$_SESSION[quatity]=implode("@",$arrayquatity);

for($i=0;$i {

$id=$array[$i];
$num=$arrayquatity[$i];

if($id!="")
{
$sql=mysql_query("select * from shangpin where id='".$id."'",$conn);
$info=mysql_fetch_array($sql);
$total1=$num*$info[huiyuanjia];
$total+=$total1;
$_SESSION["total"]=$total;
?>


 
 
 
 
 
 
 

}
}
?>

 

}
?>
您的购物车为空!
商品名称
数量
市场价
会员价
折扣
小计
操作

      >
 

     
       
         
         
         
         
       
     

 
         
总计:

 

3. File gouwu2.php

Copy code The code is as follows:


 
   
   
   
 

 
   
 
     
       
     
   
 

     
       
         
       
       
         
       
     
收货人信息


    
     
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
  
         
收货人姓名:
性别:

 
 
详细地址:

 
邮政编码:
联系电话:
电子邮箱:
送货方式:

 
支付方式:

 
 
简单留言:

 

 

 if($_GET[dingdanhao]!="")
  {  $dd=$_GET[dingdanhao];
     session_start();

     $array=explode("@",$_SESSION[producelist]);
  $sum=count($array)*20+260;
    echo" ";

  }
?>

4、数据库配置文件conn.php
 

复制代码 代码如下:

$conn=mysql_connect("localhost","root","") or die("数据库服务器连接错误".mysql_error());
mysql_select_db("shop",$conn) or die("数据库访问错误".mysql_error());
mysql_query("set character set gb2312");
mysql_query("set names gb2312");
?>

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/779566.htmlTechArticle1、商品展示页面 复制代码 代码如下: table width="255" border="0" cellspacing="0" cellpadding="0" tr td width="130" rowspan="6"div align="center" ?php if(trim($info[tu...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template