Hi folks. Thank you all so much for going through all this code and the problems that ensued. I am also a PHP newbie taking a class and using this lousy book. The number of errors in the book are amazing.
I inputted all the code that's been posted in this forum and it works great. But the code that's left to place does not work. There's a checkout.php file to allow for checkout and then there are extra classes to add quantities to the orders. I'm using the code posted in KaizerBill's post above and below is the code for the checkout.php file as well as the extra code (that I can't get to work) to add one or remove one from the quantity chart that's part of the ShoppingCart.php file.
This is the checkout.php code:
Quote:
<?php
require_once("ShoppingCart.php");
session_start();
if (!isset($_SESSION['curCart']) && $_GET['operation'] != "checkout")
header("location:GosselinGourmetGoods.php");
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Gosselin Gourmet Goods</title>
<meta http-equiv="content-type"
content="text/html; charset=iso-8859-1" />
<link rel="stylesheet" href="php_styles.css" type="text/css" />
</head>
<body>
<h1>Gosselin Gourmet Goods</h1>
<?php
$Cart = unserialize($_SESSION['curCart']);
$Cart->setTable("myorders");
$Cart->checkout();
?>
<p><a href="GosselinGourmetGoods.php">Gosselin Gourmet Goods</a></p>
</body>
</html>
|
And this is the extra code to add one or remove one that originally appears in the ShoppingCart.php code from the book:
Quote:
public function addOne() {
$ProdID = $_GET['productID'];
$this->Orders[$ProdID] += 1;
}
public function removeOne() {
$ProdID = $_GET['productID'];
$this->Orders[$ProdID] -= 1;
if ($this->Orders[$ProdID] == 0)
$this->removeItem();
}
public function checkout() {
$ProdID = $_GET['productID'];
foreach($this->Orders as $Order) {
$SQLstring = "INSERT INTO " . $this->TableName . " VALUES('" . session_id() . "','" . key($this->Orders) . "','" . $this->OrderTable[key($this->Orders)] . "'," . $Order . ")";
$QueryResult = @mysqli_query($this->DBConnect, $SQLstring)
Or die("<p>Unable to perform the query.</p>"
. "<p>Error code " . mysqli_errno($this->DBConnect)
. ": " . mysqli_error($this->DBConnect)) . "</p>";
}
|
Can anyone help me figure out if I've got this written correctly? The added code goes towards the bottom of the ShoppingCart.php script under public function emptyCart()