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

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

php购物车完整实现代码

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

1、商品展示页面

复制代码代码如下:

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

<tr>

<td width="130" rowspan="6"><dival ign="center">

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

{echo"暂无图片";

}else

{

?>

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

<?php

}

?>

</div></td>

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

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

<tr>

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

<td><font color="910800"> 【市场价 <?php echo$info[shichangjia];?>】 </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=<?phpecho$info[id];?>">查看信息</a>】 </td>

</tr>

<tr>

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

<td> 【<a href="addgouwuche.php?id=<?phpecho$info[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

复制代码代码如下:

<?phpsessi on_sta rt();include("conn.php");if($_SESSION[username]=="")

{echo"<script>alert('请先登录后购物! ');history.back();</script>";exit;

}

$id=strva l($_G ET[id]);

$sql=mysql_query("select*from shangpin where id='".$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

复制代码代码如下:

<?phpsessi on_sta rt();if($_SESSION[username]=="")

{echo"<script>alert('请先登录后购物! ');history.back();</script>";exit;

}

?>

<?phpinclude("top.php");

?>

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

<tdwidth="200" height="438"val ign="top"bgcolor="#E8E8E8"><dival ign="center">

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

</div></td>

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

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

<tr>

<td></td>

</tr>

</table>

<table width="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"><table width="500" border="0" al ign="center" cel lpadding="0"cel lspacing="1">

<?php

sessi on_sta rt();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>

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

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

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

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

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

<tdwidth="71"bgcolor="#FFFFFF"><dival 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 where id='".$id."'",$conn);

$info=mysql_fetch_array($sql);

$total1=$num*$info[huiyuanjia];

$total+=$total1;

$_SESSION["total"]=$total;

?>

<tr>

<td height="25" bgcolor="#FFFFFF"><div al ign="center"><?php echo$info[mingcheng];?></div></td>

<td height="25"bgcolor="#FFFFFF"><dival ign="center">

<input type="text" name="<?php echo$info[id];?>" size="2" class="inputcss"value=<?php echo$num;?>>

</div></td>

<td height="25" bgcolor="#FFFFFF"><div al ign="center"><?php echo $info[shichangjia];?>元</div></td>

<td height="25" bgcolor="#FFFFFF"><div al ign="center"><?php echo $info[huiyuanjia];?>元</div></td>

<td height="25" bgcolor="#FFFFFF"><div al ign="center"><?php echo@(cei l(($info[huiyuanjia]/$info[shichangjia])*100) )."%";?></div></td>

<td height="25"bgcolor="#FFFFFF"><dival ign="center"><?phpecho$info[huiyuanjia]*$num."元";?></div></td>

<td height="25" bgcolor="#FFFFFF"><div al ign="center"><a href="removegwc.php?id=<?phpecho$info[id]?>">移除</a></div></td>

</tr>

<?php

}

}

?>

<tr>

<td height="25" colspan="8"bgcolor="#FFFFFF"><div al ign="right">

<table width="500" height="25"border="0"al ign="center" cel lpadding="0" cel lspacing="0"><tr>

<tdwidth="125"><dival ign="center">

<input type="submit"value="更改商品数量" class="buttoncss">

</div></td>

<tdwidth="125"><dival ign="center"><a href="gouwu2.php">去收银台</a></div></td><td width="125"><div al ign="center"><a href="gouwu1.php?qk=yes">清空购物车</a></div></td>

<tdwidth="125"><dival ign="left">总计 <?phpecho$total;?></div></td>

</tr>

</table>

</div></td>

</tr>

<?php

}

?>

</table></td>

</tr>

</fo r m>

</table></td>

</tr>

</table>

3、文件gouwu2.php

复制代码代码如下:

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

<tdwidth="200" height="438"val ign="top"bgcolor="#E8E8E8"><dival ign="center">

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

</div></td>

<tdwidth="10"background="jiujiu360.comimages/l ine2.gif"></td>

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

<tr>

<td></td>

</tr>

</table>

<table width="550"border="0"al ign="center" cel lpadding="0" cel lspacing="0">

<tr>

<td height="25" bgcolor="#555555"><div al ign="center" style="color: #FFFFFF">收货人信息</div></td>

</tr>

<tr>

<td height="300" bgcolor="#555555"><table width="550" height="300" border="0"al ign="center" cel lpadding="0" cel lspacing="1">

<script language="javascript">

**

*购物车收货人信息

* Edit www.jb51.net

*/function chkinput(form)

{if(form.name.value=="")

{alert("请输入收货人姓名!");form.name.select();return(false);

}if(form.dz.va lue=="")

{alert("请输入收货人地址!");form.dz.select();return(false);

}if(form.yb.va lue=="")

{alert("请输入收货人邮编!");form.yb.select();return(false);

}if(form.tel .value=="")

{alert("请输入收货人联系电话!");form.tel .select();return(false);

}if(form.emai l .value=="")

{alert("请输入收货人E-mai l地址!");form.emai l .select();return(false);

}

if(form.emai l .value. indexOf("@")<0)

{alert("收货人E-mai l地址格式输入错误!");form.emai l .select();return(false);

}return(true);

}

</script>

<form name="form1"method="post"action="savedd.php"onSubmit="return chkinput(this)"><tr>

<tdwidth="100" height="25"bgcolor="#FFFFFF"><dival ign="center">收货人姓名 </div></td><td width="183" bgcolor="#FFFFFF"><div al ign="left"><input type="text" name="name"size="25" class="inputcss" style="background-color:#e8f4ff "onMouseOver="this.style.backgroundColor='#ffffff'"onMouseOut="this.style.backgroundColor='#e8f4ff'"></div></td>

<tdwidth="86"bgcolor="#FFFFFF"><div al ign="center">性别 </div></td>

<tdwidth="176"bgcolor="#FFFFFF"><dival ign="left">

<select name="***">

<option selected value="男">男</option>

<option value="女">女</option>

</select>

</div></td>

</tr>

<tr>

<td height="25"bgcolor="#FFFFFF"><dival ign="center">详细地址 </div></td>

<td height="25" colspan="3" bgcolor="#FFFFFF"><div al ign="left"><input name="dz" type="text"class="inputcss" id="dz" style="background-color:#e8f4ff "onMouseOver="this.style.backgroundColor='#ffffff'"onMouseOut="this.style.backgroundColor='#e8f4ff'" size="25">

</div></td>

</tr>

<tr>

<td height="25"bgcolor="#FFFFFF"><dival ign="center">邮政编码 </div></td>

<td height="25" colspan="3" bgcolor="#FFFFFF"><div al ign="left"><input type="text" name="yb"size="25" class="inputcss" style="background-color:#e8f4ff "onMouseOver="this.style.backgroundColor='#ffffff'"onMouseOut="this.style.backgroundColor='#e8f4ff'"></div></td>

</tr>

<tr>

<td height="25"bgcolor="#FFFFFF"><dival ign="center">联系电话 </div></td>

<td height="25" colspan="3"bgcolor="#FFFFFF"><div al ign="left"><input type="text" name="tel"size="25" class="inputcss" style="background-color:#e8f4ff "

onMouseOver="this.style.backgroundColor='#ffffff'"onMouseOut="this.style.backgroundColor='#e8f4ff'"></div></td>

</tr>

<tr>

<td height="25"bgcolor="#FFFFFF"><dival ign="center">电子邮箱 </div></td>

<td height="25" colspan="3" bgcolor="#FFFFFF"><div al ign="left"><input type="text"name="emai l" size="25" class="inputcss" style="background-color:#e8f4ff "onMouseOver="this.style.backgroundColor='#ffffff'"onMouseOut="this.style.backgroundColor='#e8f4ff'"></div></td>

</tr>

<tr>

<td height="25"bgcolor="#FFFFFF"><dival ign="center">送货方式 </div></td>

<td height="25" colspan="3"bgcolor="#FFFFFF"><div al ign="left">

<select name="shff" id="shff">

<option selected value="普通平邮">普通平邮</option>

<option value="特快专递">特快专递</option>

<option value="送货上门">送货上门</option>

<option value="个人送货">个人送货</option>

<option value="E-mai l">E-mai l</option>

</select>

</div></td>

</tr>

<tr>

<td height="25"bgcolor="#FFFFFF"><dival ign="center">支付方式 </div></td>

<td height="25" colspan="3"bgcolor="#FFFFFF"><div al ign="left">

<select name="zfff" id="zfff">

<option selected value="建设银行汇款">建设银行汇款</option>

<option value="交通银行汇款">交通银行汇款</option>

<option value="邮局汇款">邮局汇款</option>

<option value="网上支付">网上支付</option>

</select>

</div></td>

</tr>

<tr>

<td height="100"bgcolor="#FFFFFF"><dival ign="center">简单留言 </div></td>

<td height="100" colspan="3"bgcolor="#FFFFFF"><dival ign="left">

<textarea name="ly" cols="60" rows="8" class="inputcss" style="background-color:#e8f4ff "onMouseOver="this.style.backgroundColor='#ffffff'"onMouseOut="this.style.backgroundColor='#e8f4ff'"></textarea>

</div></td>

</tr>

<tr>

<td height="25" colspan="4" bgcolor="#FFFFFF"><div al ign="center"><input type="submit"value="提交订单" class="buttoncss">

7月RAKsmart独立服务器和站群服务器多款促销 G口不限量更低

如果我们熟悉RAKsmart商家促销活动的应该是清楚的,每个月的活动看似基本上一致。但是有一些新品或者每个月还是有一些各自的特点的。比如七月份爆款I3-2120仅30美金、V4新品上市,活动期间5折、洛杉矶+硅谷+香港+日本站群恢复销售、G口不限流量服务器比六月份折扣力度更低。RAKsmart 商家这个月依旧还是以独立服务器和站群服务器为主。当然也包括有部分的低至1.99美元的VPS主机。第一、I...

ZJI:香港物理服务器,2*E5-2630L/32G/480G SSD/30Mbps/2IP/香港BGP,月付520元

zji怎么样?zji是一家老牌国人主机商家,公司开办在香港,这个平台主要销售独立服务器业务,和hostkvm是同一样,两个平台销售的产品类别不一平,商家的技术非常不错,机器非常稳定。昨天收到商家的优惠推送,目前针对香港邦联四型推出了65折优惠BGP线路服务器,性价比非常不错,有需要香港独立服务器的朋友可以入手,非常适合做站。zji优惠码:月付/年付优惠码:zji 物理服务器/VDS/虚拟主机空间订...

CloudCone中国春节优惠活动限定指定注册时间年付VPS主机$13.5

CloudCone 商家产品还是比较有特点的,支持随时的删除机器按时间计费模式,类似什么熟悉的Vultr、Linode、DO等服务商,但是也有不足之处就在于机房太少。商家的活动也是经常有的,比如这次中国春节期间商家也是有提供活动,比如有限定指定时间段之前注册的用户可以享受年付优惠VPS主机,比如年付13.5美元。1、CloudCone新年礼物限定款仅限2019年注册优惠购买,活动开始时间:1月31...

php购物车为你推荐
站长故事部队里什么是站长?最低是什么级别?都有哪些级别啊?渗透测试渗透测试的专业服务arm开发板想购买一个ARM开发板,选什么类型的好办公协同软件求一款国内知名的OA办公软件,谁知道有哪些呢?唱吧电脑版官方下载电脑上可以安装唱吧吗?网店推广网站网店怎么推广?腾讯文章腾讯新闻的精选微信里面收藏的文章在哪里ios7固件下载ios 7及以上固件请在设备上点信任在哪点gbk编码表GBK码表怎么查域名库求解:请将您的域名:别名(CNAME)主机解析到idc1.xiaodoutao.com
互联网域名管理办法 edis evssl证书 权嘉云 架设服务器 php空间推荐 国外代理服务器软件 台湾谷歌 如何安装服务器系统 吉林铁通 google台湾 空间登入 河南移动梦网 shuang12 lick 上海电信测速 防cc攻击 华为k3 免费个人主页 杭州电信宽带优惠 更多