when i add a second item to cart this gives error, but not in first add item...can you debug class function, I use XAMPP
# MySQL 5.5.8
# PHP 5.3.5?
Notice: Undefined index: in C:\xampp\htdocs\Gosselin2006\Chapter.11\Chapter\Sh oppingCart.php on line 74
Unable to perform the query1.
Error code 1064:You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE productID=''' at line 1
// line 74:
$SQLstring = "SELECT * FROM ". $this->OrderTable[key($this->Orders)]." WHERE productID='".key($this->Orders)."';";
OrderTable[key($this->Orders)]=category[key(order Item)]=productTable
key($this->Orders)=key(order Item)
Code:
public function showCart() {
if (empty($this->Orders))
echo "<p>Your shopping cart is empty.</p>";
else {
echo "<table width='100%' border='1'>";
echo "<tr><th>Product</th><th>Quantity</th><th>Price Each</th></tr>";
$Total = 0;
foreach($this->Orders as $Order) {
$SQLstring = "SELECT * FROM ". $this->OrderTable[key($this->Orders)]." WHERE productID='".key($this->Orders)."';"; // 74
$QueryResult = @mysqli_query($this->DBConnect, $SQLstring) or die("<p>Unable to perform the query1.</p>"."<p>Error code ".mysqli_errno($this->DBConnect).":".mysqli_error($this->DBConnect))."</p>";
$Row=mysqli_fetch_row($QueryResult);
echo "<tr><td>{$Row[1]}</td>";
echo "<td aligh='center'>$Order </td>";
printf("<td aligh='center'>$%.2f</td></tr>",$Row[3]);
$Total += $Row[3]*$Order;
$SQLstring ="";
next($this->Orders);
} // end for each
echo "<tr><td aligh='center' colspan='2'><strong>Your Shopping Cart contains ". count($this->Orders). " product(s).</strong></td>";
printf("<td aligh='center'><strong>Total: $%.2f</strong></td>",$Total);
echo"</tr></table>";
} // end if
} // end function