购物车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);

香港E3 16G 390元/ 香港E5*2 32G 600元/ 香港站群 4-8C 1200元/ 美国200G高防 900/ 日本100M 700元

3C云国内IDC/ISP资质齐全商家,与香港公司联合运营, 已超6年运营 。本次为大家带来的是双12特惠活动,香港美国日本韩国|高速精品|高防|站群|大带宽等产品齐全,欢迎咨询问价。3C云科技有限公司官方网站:http://www.3cccy.com/客服QQ:937695003网页客服:点击咨询客户QQ交流群:1042709810价目表总览升级内存 60元 8G内存升级硬盘 1T机械 90元 2...

DogYun(300元/月),韩国独立服务器,E5/SSD+NVMe

DogYun(中文名称狗云)新上了一批韩国自动化上架独立服务器,使用月减200元优惠码后仅需每月300元,双E5 CPU,SSD+NVMe高性能硬盘,支持安装Linux或者Windows操作系统,下单自动化上架。这是一家成立于2019年的国人主机商,提供VPS和独立服务器租用等产品,数据中心包括中国香港、美国洛杉矶、日本、韩国、德国、荷兰等。下面分享这款自动化上架韩国独立服务器的配置和优惠码信息。...

TabbyCloud周年庆&七夕节活动 美國INAP 香港CN2

TabbyCloud迎来一周岁的生日啦!在这一年里,感谢您包容我们的不足和缺点,在您的理解与建议下我们也在不断改变与成长。为庆祝TabbyCloud运营一周年和七夕节,TabbyCloud推出以下活动。TabbyCloud周年庆&七夕节活动官方网站:https://tabbycloud.com/香港CN2: https://tabbycloud.com/cart.php?gid=16购买链...

php购物车为你推荐
暴风影音怎么截图请问如何在暴风影音上截图暴风影音怎么截图如何在暴风影音中截图?中国论坛大全安徽论坛都有哪些?1433端口1433端口怎么打开arm开发板arm开发板是干什么用的,是用在什么领域方面的手机区号手机号码+86是移动区号还是联通的区号?iphone越狱后怎么恢复苹果手机越狱之后能恢复原来吗?天天酷跑刷金币天天酷跑如何刷分刷金币?免费免费建站最好的免费建站什么是云平台什么是云平台管理软件,一个云平台软件应该具有哪些基本功能
域名批量查询 哈尔滨服务器租用 securitycenter 香港vps99idc 踢楼 pw域名 美国便宜货网站 光棍节日志 韩国名字大全 谁的qq空间最好看 工信部icp备案号 idc查询 爱奇艺会员免费试用 银盘服务是什么 实惠 可外链的相册 万网注册 双十二促销 .htaccess restart 更多