微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

php 购物车完整实现代码

1、商品展示页面

代码如下:
PHP
if(trim($info[tupian]==""))
{
echo "暂无图片";
}
else
{
?>
PHP
}
?>
数量:
PHP
if(($info[shuliang]-$info[cishu])>0)
{
echo ($info[shuliang]-$info[cishu]);
}
else
{
echo "已售完";
}
?>】 PHP
}
?>

2、文件addgouwuche.PHP

代码如下:
PHP
session_start();
include("conn.PHP");if($_SESSION[username]=="")
{
echo "";
exit;
}
$id=strval($_GET[id]);
$sql=MysqL_query("select * from shangpin where id='".$id."'",$conn);
$info=MysqL_fetch_array($sql);
if($info[shuliang]<=0)
{
echo "";
exit;
}
$array=explode("@",$_SESSION[producelist]);
for($i=0;$i {
if($array[$i]==$id)
{
echo "";
exit;
}
}
$_SESSION[producelist]=$_SESSION[producelist].$id."@";
$_SESSION[quatity]=$_SESSION[quatity]."1@"; header("location:gouwu1.PHP");
?>

3、文件gouwu1.PHP

代码如下:
PHP
session_start();
if($_SESSION[username]=="")
{
echo "";
exit;
}
?>
PHP
include("top.PHP");
?>

PHP">
的购物车 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
{
?>
名称 数量 PHP
/**
* 购物车 商品数量管理
* Edit www.jb51.cc
*/
$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 id='".$id."'",$conn);
$info=MysqL_fetch_array($sql);
$total1=$num*$info[huiyuanjia];
$total+=$total1;
$_SESSION["total"]=$total;
?>

>
PHP
}
}
?>
数量" class="buttoncss">
PHP
}
?>

3、文件gouwu2.PHP

代码如下:


PHP" onSubmit="return chkinput(this)">
SEOver="this.style.backgroundColor='#ffffff'" onMouSEOut="this.style.backgroundColor='#e8f4ff'">
SEOver="this.style.backgroundColor='#ffffff'" onMouSEOut="this.style.backgroundColor='#e8f4ff'" size="25">
SEOver="this.style.backgroundColor='#ffffff'" onMouSEOut="this.style.backgroundColor='#e8f4ff'">SEOver="this.style.backgroundColor='#ffffff'" onMouSEOut="this.style.backgroundColor='#e8f4ff'">SEOver="this.style.backgroundColor='#ffffff'" onMouSEOut="this.style.backgroundColor='#e8f4ff'">



PHP
if($_GET[dingdanhao]!="")
{ $dd=$_GET[dingdanhao];
session_start(); $array=explode("@",$_SESSION[producelist]);
$sum=count($array)*20+260;
echo" "; }
?>

4、数据库配置文件conn.PHP

代码如下:
PHP
$conn=MysqL_connect("localhost","root","") or die("数据库服务器连接错误".MysqL_error());
MysqL_select_db("shop",$conn) or die("数据库访问错误".MysqL_error());
MysqL_query("set character set gb2312");
MysqL_query("set names gb2312");
?>

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐