When I try and select the item, the item needs to show up and the quantity amount so i can add it to the cart. I can't get it to work. I need to the following:
Here's the order of how things should happen on store.php: check if $_GET['item'] is numeric convert it to an integer and store it in a variable set a flag to true ($valid_item) echo the item ID, price, and form
<?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>