1、商品展示页面
复制代码 代码如下:
<table cellspacing="0" cellpadding="0">
<tr>
<td rowspan="6"><div>
<?php
if(trim($info[tupian]==""))
{
echo "暂无图片";
}
else
{
?>
<img src="<?php echo $info[tupian];?>">
<?php
}
?>
</div></td>
<td> </td>
<td><font color="EF9C3E">【<?php echo $info[mingcheng];?>】</font></td>
</tr>
<tr>
<td> </td>
<td><font color="910800">【市场价:<?php echo $info[shichangjia];?>】</font></td>
</tr>
<tr>
<td> </td>
<td><font color="DD4679">【会员价:<?php echo $info[huiyuanjia];?>】</font></td>
</tr>
<tr>
<td> </td>
<td>【<a href="lookinfo.php?id=https://www.jb51.net/<?php echo $info[id];?>">查看信息</a>】</td>
</tr>
<tr>
<td> </td>
<td>【<a href="addgouwuche.php?id=https://www.jb51.net/<?php echo $info[id];?>">放入购物车</a>】</td>
</tr>
<tr>
<td> </td>
<td><font color="13589B">【剩余数量:
<?php
if(($info[shuliang]-$info[cishu])>0)
{
echo ($info[shuliang]-$info[cishu]);
}
else
{
echo "已售完";
}
?>】</font></td>
</tr>
</table>
<?php
}
?>
</table>
2、文件addgouwuche.php
复制代码 代码如下:
<?php
session_start();
include("conn.php");
if($_SESSION[username]=="")
{
echo "<script>alert('请先登录后购物!');history.back();</script>";
exit;
}
$id=strval($_GET[id]);
$sql=mysql_query("select * from shangpin where",$conn);
$info=mysql_fetch_array($sql);
if($info[shuliang]<=0)
{
echo "<script>alert('该商品已经售完!');history.back();</script>";
exit;
}
$array=explode("@",$_SESSION[producelist]);
for($i=0;$i<count($array)-1;$i++)
{
if($array[$i]==$id)
{
echo "<script>alert('该商品已经在您的购物车中!');history.back();</script>";
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 "<script>alert('请先登录,后购物!');history.back();</script>";
exit;
}
?>
<?php
include("top.php");
?>
<table cellpadding="0" cellspacing="0">
<tr>
<td valign="top" bgcolor="#E8E8E8"><div>
<?php include("left.php");?>
</div></td>
<td background="images/line2.gif"> </td>
<td valign="top"><table cellpadding="0" cellspacing="0">
<tr>
<td> </td>
</tr>
</table>
<table cellpadding="0" cellspacing="0">
<form method="post" action="gouwu1.php">
<tr>
<td bgcolor="#555555"><div><?php echo $_SESSION[username];?>的购物车</div></td>
</tr>
<tr>
<td bgcolor="#555555"><table cellpadding="0" cellspacing="1">
<?php
session_start();
session_register("total");
if($_GET[qk]=="yes")
{
$_SESSION[producelist]="";
$_SESSION[quatity]="";
}
$arraygwc=explode("@",$_SESSION[producelist]);
$s=0;
for($i=0;$i<count($arraygwc);$i++)
{
$s+=intval($arraygwc[$i]);
}
if($s==0 )
{
echo "<tr>";
echo" <td colspan='6' bgcolor='#FFFFFF'>您的购物车为空!</td>";
echo"</tr>";
}
else
{
?>
<tr>
<td bgcolor="#FFFFFF"><div>商品名称</div></td>
<td bgcolor="#FFFFFF"><div>数量</div></td>
<td bgcolor="#FFFFFF"><div>市场价</div></td>
<td bgcolor="#FFFFFF"><div>会员价</div></td>
<td bgcolor="#FFFFFF"><div>折扣</div></td>
<td bgcolor="#FFFFFF"><div>小计</div></td>
<td bgcolor="#FFFFFF"><div>操作</div></td>
</tr>
<?php
/**
* 购物车 商品数量管理
* Edit
*/
$total=0;
$array=explode("@",$_SESSION[producelist]);
$arrayquatity=explode("@",$_SESSION[quatity]);
while(list($name,$value)=each($_POST))
{
for($i=0;$i<count($array)-1;$i++)
{
if(($array[$i])==$name)
{
$arrayquatity[$i]=$value;
}
}
}
$_SESSION[quatity]=implode("@",$arrayquatity);