當用戶選擇要購買的物品時,我已經設法讓一個庫存表顯示在購物車頁面中,但我無法弄清楚如何從不同的頁面獲取多個表格來顯示。 任何幫助,將不勝感激!購物車php mysql
<?php
session_start();
$cart=$_SESSION["cart"];
extract($_POST);
if (IsSet($productid)||IsSet($_SESSION["notempty"])) $empty=false;
else $empty=true;
if (!$empty)
{
if (IsSet($cart[$productid])) $cart[$productid]+=$quantity;
else $cart[$productid]=$quantity;
$_SESSION["notempty"]=true;
}
$_SESSION["cart"]=$cart;
$conn=mysql_connect("","");
mysql_select_db("webent",$conn);
mysql_query("CREATE TABLE Stock (stock_ID INT(3) NOT NULL PRIMARY KEY AUTO_INCREMENT,
itemName VARCHAR(50),itemDesc VARCHAR(100),
itemImage VARCHAR(10),itemStock VARCHAR(3),
itemPrice VARCHAR(5))");
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" dir="ltr">
<head>
<title>Jus' Books</title>
<link href="style2.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="container">
<div id="masthead">
</div>
<div id="navigation">
<p><a href="index1.php">Home</a>
<a href="fiction.php">Fiction</a>
<a href="travel.php">Travel</a>
<a href="sport.php">Sport</a>
<a href="arts.php">Arts & Design</a>
<a href="cart.php">Shopping Cart</a>
<a href="account.php">Manage Account</a></p>
</div>
<div id="content">
<?php
if ($empty) echo "<h4>Your shopping cart is empty</h4>";
else
{
echo "<h4>Your shopping cart contains:</h4>";
$total="";
foreach ($cart as $id=>$no)
{
if ($id!="")
{
$result=mysql_query("SELECT * FROM Stock WHERE stock_ID= $id");
$row=mysql_fetch_array($result);
extract($row);
if ($itemStock<$no) $no=$itemStock;
echo "<p>$no units of item $itemName at $itemPrice each</p>";
}
$total+=$no*$itemPrice;
}
echo "<p>Total to pay: £$total</p>";
}
?>
<a href="index1.php">Continue Shopping</a>
<a href="checkout.php">Proceed to Checkout</a>
<p></p>
</div>
<div id="footer">
<p><a href="index1.php">Home</a> |
<a href="fiction.php">Fiction</a> |
<a href="travel.php">Travel</a> |
<a href="sport.php">Sport</a> |
<a href="arts.php">Arts & Design</a> |
<a href="cart.php">Shopping Cart</a> |
<a href="account.php">Manage Account</a></p>
</div>
</div>
</body>
</html>
的其它表有相同的字段,但有名字Stock_Travel Stock_Sport Stock_Arts
**警告**您的代碼容易受到SQL注入攻擊。 – 2012-03-27 12:37:19