php 购物车完整实现代码
发布时间:2020-12-12 20:12:45 所属栏目:PHP教程 来源:网络整理
导读:1、商品展示页面 代码如下: if(trim($info[tupian]=="")) { echo "暂无图片"; } else { ?> " width="130" height="100" border="0" } ?> 】 】 】 if(($info[shuliang]-$info[cishu])>0) { echo ($info[shuliang]-$info[cishu]); } else { echo "已售完"; }
1、商品展示页面 代码如下:
?> |
2、文件addgouwuche.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");
?>
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
代码如下:
session_start();
if($_SESSION[username]=="")
{
echo "";
exit;
}
?>
include("top.php");
?>
if($_SESSION[username]=="")
{
echo "";
exit;
}
?>
include("top.php");
?>
3、文件gouwu2.php
代码如下:
{ $dd=$_GET[dingdanhao];
session_start(); $array=explode("@",$_SESSION[producelist]);
$sum=count($array)*20+260;
echo" "; }
?>
4、数据库配置文件conn.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");
?>
mysql_select_db("shop",$conn) or die("数据库访问错误".mysql_error());
mysql_query("set character set gb2312");
mysql_query("set names gb2312");
?>
(编辑:李大同)
【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!