Home > php教程 > php手册 > php 购物车完整实现代码

php 购物车完整实现代码

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-06 20:22:10
Original
1676 people have browsed it

本文介绍一个php实现的购物车代码,功能实现比较完整,实现了购物车、订货人信息、会员价等功能,还是不错的,有需要的朋友,可以参考下

1、商品展示页面

复制代码 代码如下:





 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

        if(trim($info[tupian]==""))
     {
       echo "暂无图片";
     }
     else
     {
?>
php 购物车完整实现代码
  }
?>
 
  【市场价:
  【会员价:
  查看信息
  放入购物车
  【剩余数量:
            if(($info[shuliang]-$info[cishu])>0)
      {
         echo ($info[shuliang]-$info[cishu]);
      }
      else
      {
         echo "已售完";
      }
      ?>】

           }
     ?>    

2、文件addgouwuche.php

复制代码 代码如下:


session_start();
include("conn.php");

if($_SESSION[username]=="")
 {
  echo "<script>alert('请先登录后购物!');history.back();</script>"; 
  exit;
 }
  $id=strval($_GET[id]);
$sql=mysql_query("select * from shangpin where",$conn); 
$info=mysql_fetch_array($sql);
if($info[shuliang] {
   echo "<script>alert('该商品已经售完!');history.back();</script>";
   exit;
 }
  $array=explode("@",$_SESSION[producelist]);
  for($i=0;$i    {
  if($array[$i]==$id)
   {
      echo "<script>alert('该商品已经在您的购物车中!');history.back();</script>";
   exit;
   }
 }
  $_SESSION[producelist]=$_SESSION[producelist].$id."@";
  $_SESSION[quatity]=$_SESSION[quatity]."1@";

  header("location:gouwu1.php");
?>

3、文件gouwu1.php

复制代码 代码如下:


 session_start();
 if($_SESSION[username]=="")
  {
    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
*/
$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",$conn);
       $info=mysql_fetch_array($sql);
       $total1=$num*$info[huiyuanjia];
       $total+=$total1;
       $_SESSION["total"]=$total;
   ?>


 
 
 
 
 
 
 

         }
     }
?>

 
 
     }
   ?>

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

      >
 

     
       
         
         
         
         
       
     

 
         
总计:

 

3、文件gouwu2.php

复制代码 代码如下:

Related labels:
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
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template