【php开源代码栏目提醒】:网学会员--在 php开源代码编辑为广大网友搜集整理了:add_item.php绩等信息,祝愿广大网友取得需要的信息,参考学习。
<?php
//
// add_item.php:
// Add an item to the shopping cart.
//
session_start();
if (session_is_registered('cart')) {
session_register('cart');
}
require 'lib.inc.php'; // LoadProducts()
LoadProducts(); // Load products in $master_products_list
// Make $curr_product global
$curr_product = array();
// Loop through all the products and pull up the product
// that we are interested in
foreach ($master_products_list as $prod_id => $product) {
if (trim($prod_id) == trim($_GET[id])) {
$curr_product = $product;
}
}
// Register our session
//session_register('cart');
//if(session_is_registered('cart')) echo "已经
注册";
if ($_POST[ordered]) { // If they have chosen the product
array_push($_SESSION[cart][products], array(trim($_POST[id]), $_POST[quantity]));
$_SESSION[cart][num_items] += $_POST[quantity];
}
?>
<html>
<head>
<title>
<?php if ($_POST[ordered]) { ?>
已经添加 <?php echo $curr_product[name]; ?> 到您的购物篮
<?php } else { ?>
添加 <?php echo $curr_product[name]; ?> 到您的购物篮
<?php } ?>
</title>
</head>
<body>
<?php if ($_POST[ordered]) { ?>
<h1><?php echo $curr_product[name]; ?>
添加至购物篮成功</h1>
<a href="cart.php">返回</a> 商品
列表页面.
<?php } else { ?>
<h1>添加 <?php echo $curr_product[name]; ?> 到您的购物篮</h1>
<form action="<?php echo $
PHP_SELF; ?>" method="post">
商品名称: <?php echo $curr_product[name]; ?>
<br>
商品说明: <?php echo $curr_product[desc]; ?>
<br>
商品单价: RMB<?php echo $curr_product[price]; ?>
<br>
商品数量: <input type="text" size="7" name="quantity">
<input type="hidden" name="id" value="<?php echo $_GET[id]; ?>">
<input type="hidden" name="ordered" value="1">
<input type="submit" value="添加至购物栏">
</form>
<?php } ?>
</body>
</html>