<?php
//Start the session
session_start();

require_once("classes.php");



?>
<html>
<head>
<title>Add an item</title>
</head>
<body>
<?php
if (empty($_POST['item']) || empty($_POST['price']) || empty($_POST['quantity'])) {
	//Not all fields have been specified!
	echo "<h1>Error</h1>";
	echo "<p>You need to specify all the required fields!</p>";
	//We need to print out the footer too, because we're exiting out of the script
	echo "</body></html>";
	exit;
}

//Read in variables from $_POST
$price     = $_POST['price'];
$itemname  = $_POST['item'];
$quantity  = $_POST['quantity'];
?>

<h1>Add to cart</h1>
<p>Thank you for wanting a <strong><? echo $itemname; ?></strong>!</p>

<?
$item = new Item($itemname, $price, $quantity);

// Add the item to the $_SESSION['cart'] session variable
$_SESSION['cart'][$item->getName()] = $item;

$item->name;

echo "<p>Your item has been added to the cart.</p>";

echo "<a href=\"cart.php\">Go to cart!</a>";

?>
</body>
</html>
