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

CloudCone(12.95美元/月CN2 GT线路,KVM架构1 Gbps带宽

整理一下CloudCone商家之前推送的闪购VPS云服务器产品,数量有限,活动推出可能很快机器就售罄了,有需要美国便宜VPS云服务器的朋友可以关注一下。CloudCone怎么样?CloudCone服务器好不好?CloudCone值不值得购买?CloudCone是一家成立于2017年的美国服务器提供商,国外实力大厂,自己开发的主机系统面板,CloudCone主要销售美国洛杉矶云服务器产品,优势特点是...

41云,服务器8折优惠券,200G TCP防御

41云怎么样?41云是国人主机品牌,目前经营产品有国内外云服务器、CDN(高防CDN)和物理机,其中国内外云服务器又细分小类有香港限流量VPS、香港大带宽VPS、香港弹性自选VPS、香港不限流VPS、香港BGP线路VPS、香港Cera+大带宽机器、美国超防VPS、韩国原生VPS、仁川原生VPS、日本CN2 VPS、枣庄高防VPS和金华高防VPS;物理机有美国Cera服务器、香港单程CN2服务器、香...

提速啦 韩国服务器 E3 16G 3IP 450元/月 韩国站群服务器 E3 16G 253IP 1100元/月

提速啦(www.tisula.com)是赣州王成璟网络科技有限公司旗下云服务器品牌,目前拥有在籍员工40人左右,社保在籍员工30人+,是正规的国内拥有IDC ICP ISP CDN 云牌照资质商家,2018-2021年连续4年获得CTG机房顶级金牌代理商荣誉 2021年赣州市于都县创业大赛三等奖,2020年于都电子商务示范企业,2021年于都县电子商务融合推广大使。资源优势介绍:Ceranetwo...

php购物车为你推荐
郭吉军二战中受害最大的国家?主页改不了为什么我电脑的主页改不了了?在线漏洞检测如何查看网站的漏洞?flash导航条如何添加FLASH导航条显卡温度多少正常显卡温度多少算正常?网易公开课怎么下载怎么下载网易公开课里的视频 .......保护气球什么气球可以骑?xp系统停止服务XP系统停止服务后电脑怎么办?网页打开很慢如何解决网速正常 网页打开很慢问题微信电话本怎么用微信电话本好用吗
php空间租用 中国万网虚拟主机 tier koss 工作站服务器 789电视网 免费网页空间 上海服务器 便宜空间 摩尔庄园注册 大化网 阿里云邮箱个人版 网络速度 小夜博客 移动王卡 windowssever2008 webmin e-mail ping值 美国西雅图独立 更多