验证购物车

时间:2012-03-24 04:40:05

标签: php

当我尝试选择项目时,项目需要显示和数量,以便我可以将其添加到购物车。我无法让它发挥作用。我需要以下内容:

以下是store.php上应该如何发生的顺序: 检查$ _GET ['item']是否为数字 将其转换为整数并将其存储在变量中 将标志设置为true($ valid_item) 回显商品ID,价格和表格

    <?php
     require_once 'lib.php';

     redirect_if_offline();


     ?>

     <html>

     <head>
     <link rel="stylesheet" type="text/css" href="style.css" />
     </head>

     <body>
     <div id="wrapper">
     <?php require_once 'left.php'; ?>
     <div id="main">

     <h2>PHP Store Demo</h2>
     <br />

     <h2>
     <?php


    /******************************************************
     - Validate the item ID:
     - If there is no item ID specified, display a welcome message.
     - If an item ID is not valid, display an error message.
     - If it is a valid item ID, display the item name and price,
     and provide a form to add items to the cart.
     - hint: your form should use GET, and there needs to be
     a hidden form element with the item ID. Example:
     -<input type='hidden' name='item' value='<?php echo $itemID; ?>' />
    *****************************************************/

     if (isset($_GET['item'])){
    echo $valid_item ?"{$items[$item][0]} --- \$$price" : "Invalid item";
    }
    else{

    echo "Welcome to the PHP Store.";
    }
    ?>

    </h2>

    <?php

   if ($valid_item) {
   $cart = $_SESSION['cart'];
   if ($cart) {
    $cart .= ','.$_GET['item'];
   } else {
    $cart = $_GET['item'];
   }
   $_SESSION['cart'] = $cart;



    echo " 
    <form action='cart.php' method='get'>
    <input type='hidden' name='item' value='true' value='<?php echo $item; ?i>' />
    <input type='text' name='qty' value='1' />
    <input name='submit' type = 'submit' value='Add to the cart' />

    </form>";
     }



     ?>

     </div>
     </div>
     </body>

     </html>

0 个答案:

没有答案