Php 验证购物车

Php 验证购物车,php,Php,当我尝试并选择该项目时,该项目需要显示和数量金额,以便我可以将其添加到购物车。我不能让它工作。我需要: 下面是store.php上的操作顺序: 检查$\u GET['item']是否为数字 将其转换为整数并存储在变量中 将标志设置为true($valid\u item) 回显项目ID、价格和表单 <?php require_once 'lib.php'; redirect_if_offline(); ?> <html>

当我尝试并选择该项目时,该项目需要显示和数量金额,以便我可以将其添加到购物车。我不能让它工作。我需要:

下面是store.php上的操作顺序: 检查$\u GET['item']是否为数字 将其转换为整数并存储在变量中 将标志设置为true($valid\u 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>

PHP商店演示


$valid\u item
变量来自何处?