购物车php 购物车完整实现代码

php购物车  时间:2021-02-09  阅读:()

php购物车完整实现代码

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

1、商品展示页面

复制代码代码如下:

<tablewidth="255"border="0" cel lspacing="0" cel lpadding="0">

<tr>

<td width="130" rowspan="6"><div al ign="center">

<?phpif(trim($info[tupian]==""))

{echo"暂无图片";

}else

{

?>

< imgsrc="<?php echo$info[tupian];?>"width="130"height="100"border="0"><?php

}

?>

</div></td>

<td width="20" height="16"></td>

<td width="113"><font color="EF9C3E"> 【<?php echo$info[mingcheng];?>】</font></td></tr>

<tr>

<td height="16"></td>

<td><font color="910800"> 【市场价 <?php echo$info[shichangji a];?>】</font></td></tr>

<tr>

<td height="16"></td>

<td><font color="DD4679"> 【会员价 <?php echo$info[huiyuanjia];?>】</font></td></tr>

<tr>

<td height="16"></td>

<td> 【<a href="lookinfo.php?id=<?php echo

$i nfo[id];?>">查看信息</a>】</td></tr>

<tr>

<td height="16"></td>

<td> 【<a href="addgouwuche.php?id=<?phpecho$i nfo[id];?>">放入购物车</a>】</td></tr>

<tr>

<td height="16"></td>

<td><font color="13589B"> 【剩余数量<?phpif(($info[shul iang]-$info[cishu])>0)

{echo($info[shul iang]-$info[cishu]);

}else

{echo"已售完";

}

?>】</font></td>

</tr>

</table>

<?php

}

?>

</table>

2、文件addgouwuche.php

复制代码代码如下:

<?phpsession_start();include("conn.php");

if($_SESSION[username]=="")

{echo"<script>alert('请先登录后购

物!');history.back();</script>"; exit;

}

$id=strval($_GET[id]);

$sql=mysql_query("select * from shangpin whereid='".$id."'",$conn); $info=mysql_fetch_array($sql);if($info[shul iang]<=0)

{echo"<script>alert('该商品已经售

完!');history.back();</script>";exit;

}

$array=explode("@",$_SESSION[producel ist]);for($i=0;$i<count($array)-1;$i++)

{if($array[$i]==$id)

{echo"<script>alert('该商品已经在您的购物车中!');history.back();</script>";exit;

}

}

$_SESSION[producel ist]=$_SESSION[producel ist].$id."@";

$_SESSION[quatity]=$_SESSION[quatity]."1@";header("location:gouwu1.php");

?>

3、文件gouwu1.php

复制代码代码如下:

<?phpsession_start();if($_SESSION[username]=="")

{echo"<script>alert('请先登录后购

物!');history.back();</script>";exit;

}

?>

<?phpinclude("top.php");

?>

<tablewidth="800" height="438"border="0" al ign="center"cel lpadding="0" cel lspacing="0"><tr>

<td width="200" height="438"val ign="top"

bgcolor="#E8E8E8"><div al ign="center">

<?phpinclude("left.php");?>

</div></td>

<td width="10"background="images/l ine2.gif"></td>

<td width="590"val ign="top"><tablewidth="550" height="10"border="0" al ign="center" cel lpadding="0" cel lspacing="0">

<tr>

<td></td>

</tr>

</table>

<tablewidth="500"border="0"al ign="center" cel lpadding="0"cel lspacing="0">

<form name="form1"method="post" action="gouwu1.php">

<tr>

<td height="25"bgcolor="#555555"><div al ign="center"style="color:#FFFFFF"><?php echo$_SESSION[username];?>的购物车</div></td>

</tr>

<tr>

<td bgcolor="#555555"><tablewidth="500"border="0"al ign="center" cel lpadding="0" cel lspacing="1">

<?php

session_start();session_register("total");if($_GET[qk]=="yes")

{

$_SESSION[producel ist]="";

$_SESSION[quatity]="";

}

$arraygwc=explode("@",$_SESSION[producel ist]);

$s=0;for($i=0;$i<count($arraygwc);$i++)

{

$s+=intval($arraygwc[$i]);

}if($s==0)

{echo"<tr>";echo"<td height='25' colspan='6'bgcolor='#FFFFFF' al ign='center'>您的购物车为空!</td>";echo"</tr>";

}else

{

?>

<tr>

<td width="125" height="25"bgcolor="#FFFFFF"><dival ign="center">商品名称</div></td><td width="52"bgcolor="#FFFFFF"><div al ign="center">数量</div></td>

<td width="64"bgcolor="#FFFFFF"><div al ign="center">市场价</div></td>

<td width="64" bgcolor="#FFFFFF"><div al ign="center">会员价</div></td>

<td width="51"bgcolor="#FFFFFF"><div al ign="center">折扣</div></td>

<td width="66"bgcolor="#FFFFFF"><div al ign="center">小计</div></td>

<td width="71"bgcolor="#FFFFFF"><div al ign="center">操作</div></td>

</tr>

<?php

**

*购物车商品数量管理

* Edit www.jb51.net

*/

$total=0;

$array=explode("@",$_SESSION[producel ist]);$arrayquatity=explode("@",$_SESSION[quatity]);whi le(l ist($name,$value)=each($_POST))

{for($i=0;$i<count($array)-1;$i++)

{if(($array[$i])==$name)

{

$arrayquatity[$i]=$value;

}

}

}

$_SESSION[quatity]=implode("@",$arrayquatity);for($i=0;$i<count($array)-1;$i++)

{

$id=$array[$i];

$num=$arrayquatity[$i];if($id!="")

{

$sql=mysql_query("select * from shangpin whereid='".$id."'",$conn);

$info=mysql_fetch_array($sql);

PQ.hosting全线9折,1Gbps带宽不限流量VPS/€3/月,全球11大机房可选

Hostadvice主机目录对我们的服务进行了测试,然后给PQ.hosting颁发了十大WordPress托管奖。为此,宣布PQ.Hosting将在一周内进行折扣优惠,购买和续订虚拟服务器使用优惠码:Hostadvice ,全部优惠10%。PQ.hosting,国外商家,成天于2019年,正规公司,是全球互联网注册商协会 RIPE 的成员。主要是因为提供1Gbps带宽、不限流量的基于KVM虚拟的V...

Hostodo美国独立日优惠套餐年付13.99美元起,拉斯维加斯/迈阿密机房

Hostodo又发布了几款针对7月4日美国独立日的优惠套餐(Independence Day Super Sale),均为年付,基于KVM架构,采用NVMe硬盘,最低13.99美元起,可选拉斯维加斯或者迈阿密机房。这是一家成立于2014年的国外VPS主机商,主打低价VPS套餐且年付为主,基于OpenVZ和KVM架构,产品性能一般,支持使用PayPal或者支付宝等付款方式。商家客服响应也比较一般,推...

搬瓦工最新套餐KVM,CN2线路

搬瓦工在国内非常流行的主机商,以提供低价的vps著称.不过近几年价格逐渐攀升.不过稳定性和速度一向不错.依然深受国内vps爱好者喜爱.新上线的套餐经常卖到断货.支持支付宝,paypal很方便购买和使用.官网网站:https://www.bandwagonhost.com[不能直接访问,已墙]https://www.bwh88.net[有些地区不能直接访问]https://www.bwh81.net...

php购物车为你推荐
解压程序手机怎么解压文件weipin唯品购,weipuvip,是诈骗网站么?充了钱之后提不出,各种套路继续充钱手游运营手册2019新个税主要内容有哪些?可以简单说明一下吗?bbsxp怎么用 CUTEFTP上传BBSXP到FTP服务器flash导航条FLASH导航条 怎么加入链接?ps抠图技巧ps的抠图技巧是什么9flash怎么使用ePSXe啊?ios7固件下载iOS的固件有正版盗版之分吗?我看到了蜂威网有iOS7的固件想下载试用一下,那里是测试版是正版吗数据库损坏数据库损坏是怎么回事啊?qq空间打扮如何打扮QQ空间?
河南虚拟主机 fc2最新域名 免费域名注册网站 哈尔滨服务器租用 租服务器价格 cn域名备案 中国万网虚拟主机 linode日本 java主机 国外bt 网通代理服务器 华为4核 卡巴斯基永久免费版 华为网络硬盘 200g硬盘 hkg 流量计费 卡巴斯基破解版 双线asp空间 华为k3 更多