貨品不能加入購物車

加入購物車PHP
<?php

if(!isset($_SESSION['cart_items'])){
$_SESSION['cart_items'] = array();
}

session_start();

$id = isset($_POST['id']) ? $_POST['id'] : "1";
$name = isset($_POST['name']) ? $_POST['name'] : "";

$host = "***";
$uname = "***";
$pass = "***";
$database = "***";
$tablename = "***";

if(!$link = mysql_connect ($host, $uname, $pass))
exit("***");

// Select a database from MySQL
if(!$result = mysql_select_db($database, $link))
exit("***");

if(array_key_exists($pid, $_SESSION['cart_items'])){
// redirect to product list and tell the user it was added to cart
header('Location: products.php?action=exists&id' . $id . '&name=' . $name);
}

// else, add the item to the array
else{
$_SESSION['cart_items'][$pid]=$name;
// redirect to product list and tell the user it was added to cart
header('Location: products.php?action=added&id' . $id . '&name=' . $name);
}
?>

會是上面的If else出了問題嗎?


購物車PHP
<?php

session_start();

$action = isset($_POST['action']) ? $_POST['action'] : "";
$id = isset($_POST['id']) ? $_POST['id'] : "1";
$name = isset($_POST['name']) ? $_POST['name'] : "";
$rice = isset($_POST['price']) ? $_POST['price'] : "";

$host = "***";
$uname = "***";
$pass = "***";
$database = "***";
$tablename = "***";

if(!$link = mysql_connect ($host, $uname, $pass))
exit("***");

// Select a database from MySQL
if(!$result = mysql_select_db($database, $link))
exit("***");

$query = "SELECT id, name, price FROM *** ORDER BY name";
if(!$result = mysql_query ($query, $link))
exit("***");

if(!$rec = mysql_fetch_array ($result)){
echo ("***");
}

else {

echo "<br />";
echo "";

echo "";
echo "";
echo "";
echo "";
echo "";

$total_price=0;

echo "";
echo "";
echo "";
echo "";
echo "";
echo "";

$total_price+=$price;
}

echo "";
echo "";
echo "";
echo "";
echo "";

while ($rec = mysql_fetch_array ($result));
echo "

Product Name

Price

Action

{$name}${$price}";
echo " Remove from cart
Total${$total_price}";
echo "";
echo " Checkout";
echo "
";
echo "
";

// Release the Result Set
mysql_free_result($result);

// Close the connection
mysql_close($link);
?>

評論

Sign In or Register to comment.