<?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> |