【php开源代码栏目提醒】:网学会员在php开源代码频道为大家收集整理了shoppingbasket.php提供大家参考,希望对大家有所帮助!
<?php
//使用session记录一些变量
session_start();
session_register("user_id");
session_register("user_name");
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>我的购物车</title>
<base target="_self">
<link rel="stylesheet" href="chaoshi.css">
</head>
<body>
<?php
//连接到MySQL服务器
$db_host = "localhost";
$db_user = "root";
$db_pass = "770408";
$db_name = "shopping";
$link = @mysql_connect($db_host, $db_user, $db_pass);
if (!$link)
{
mysql_die();
}
//选择数据库
@mysql_select_db($db_name);
//判断用户是否已经登录
if ($user_id == "")
{
echo "<H3 align='center'>您还没有登录呢。</H3><br>";
exit();
}
//得到用户的记录号
$key_users = $user_id;
//是否要删除记录
if ($canc > 0)
{
$query = "delect from shopping where key_users='$key_users' and key_goods='$canc' and key_requests='0'";
@mysql_query($query, $link);
}
//是否要删除全部记录
if ($canc == -1)
{
$query = "delect from shopping where key_users='$key_users' and key_requests='0'";
@my
sql_query($query, $link);
}
$canc = 0;
//查询出所有属于该用户的记录
//该记录的key_requests字段应该为0
$query = "select * from shopping where key_users='$key_users' and key_requests='0'";
//得到
查询结果
$result =
mysql_query($query, $link);
$num = mysql_num_rows($result);
//判断用户是否买过东西
if ($num == 0)
{
echo "<H3 align='center'>您的购物车中没有东西!</H3><br>";
exit();
}
//如果购买过,就将它们显示出来
else
{
?>
<div align="left">
<table border="1" width="442" height="119">
<tr>
<td width="442" height="42" valign="top" colspan="6">
<h3 align="center">我的购物车</h3>
</td>
</tr>
<tr>
<td widhth="36" height="19" valign="middle" align="center">
<font class="myfont2">编号</font>
</td>
<td width="204" height="19" valign="middle" align="center">
<font class="myfont2">商品</font>
</td>
<td width="51" height="19" valign="middle" align="center">
<font class="myfont2">单价</font>
</td>
<td width="30" height="19" valign="middle" align="center">
<font class="myfont2">数量</font>
</td>
<td width="45" height="19" valign="middle" align="center">
<font class="myfont2">价格</font>
</td>
<td width="46" height="19" valign="middle" align="center">
</td>
</tr>
<?php
$num = 1;
while ($row=mysql_fetch_array($result))
{
$query = "select * from goods where key_goods='".$row['key_goods']."'";
$result1 = mysql_query($query, $link);
$row1 = mysql_fetch_array($result1);
$href_string = "<a href=\"shoppingbasket.php?canc=";
$href_string = $href_string.$row['key_goods']."\">";
?>
<tr>
<td width="36" height="21" valign="middle" align="center">
<font class="myfont3"><?print $num++;?></font>
</td>
<td width="204" height="21" valign="middle" align="center">
<font class="myfont3"><?print $num++;?></font>
</td>
<td width="51" height="21" valign="middle" align="center">
<font class="myfont3">
<?php
$display_price = sprintf("%.2f", $row1['price']/100);
print $display_price;
?>
</font>
</td>
<td width="30" height="21" valign="middle" align="center">
<font class="myfont3"><?print $row1['good_nums'];?></font>
</td>
<td width="36" height="21" valign="middle" align="center">
<font class="myfont3">
<?php
$display_price = sprintf("%.2f", $row1['price']*$row['goods_num']/100);
print $display_price;
?>
</font>
</td>
<td width="36" height="21" valign="middle" align="center">
<?print $href_string;?>删除</a>
</td>
</tr>
<?php
}
}
?>
<tr>
<td width="412" height="23" valign="bottom" colspan="6">
<p align="center">
<a href="" onclick="eval('window.close()')">继续购物</a>
<a href="bank.php">去收银台</a>
<a href="shoppingbasket.php?canc=-1">全部删除</a>
</p>
</td>
</tr>
</table>
</div>
</body>
</html>