Hello, I looking for some beginner help. I am making a basic e-commerce site and have been getting Undefined variable errors for my product page, I have declared them in the top php block and called them in the form. I have been trying to fix these errors but cant see anything wrong with the code, I know its not a connecting to MySQL problem as other pages have worked. If anyone can help I would be very grateful.
_________________________________________________________________________________________________________________________________________________
Code Listing:
<?php
//Error reporting
error_reporting(E_ALL);
ini_set('display_errors', '1');
?>
<?php
//check to see if the variable exists in the database
if(isset($_GET['id'])){
include "storescripts/connect_mysql.php";
$sql = mysql_query("SELECT * FROM products WHERE id='$id' LIMIT 1");
$productCount = mysql_num_rows($sql); // count the output amount
if ($productCount > 0) {
//get product details details
while($row = mysql_fetch_array($sql)){
$product_name = $row["product_name"];
$price = $row["price"];
$description = $row["description"];
$category = $row["category"];
$subcategory = $row["subcategory"];
}
} else {
echo "That item does not exist.";
exit();
}
}
mysql_close();
?>
<!doctype html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title><?php echo $product_name; ?></title>
<link rel="stylesheet" href="style/standard_style.css" type="text/css"media="screen" />
</head>
<body>
<div a align="center"id="mainWrapper">
<?php include_once("template_header.php");?>
<div id="PageContent">
<table width="100%" border="0" cellspacing="0" cellpadding="15">
<tr>
<td width="22%" valign="top"><img src="inventory_images/<?php echo $id; ?>.jpg" width="181" height="188" alt="<?php echo $product_name; ?>" /></td>
<td width="78%" valign="top"><h3><?php echo $product_name; ?></h3>
<p>
<?php echo $price; ?><br />
<br />
<?php echo $category; ?>
<?php echo $subcategory; ?> <br />
<br />
<?php echo $description; ?>
<br />
</p>
<form id="form1" name="form1" method="post" action="cart.php">
<input type="hidden" name="pid" id="pid" value="<?php echo $id; ?>" />
<input type="submit" name="button" id="button" value="Add to Shopping Cart" />
</form>
</td>
</tr>
</table>
</div>
<?php include_once("template_footer.php"); ?>
</div>
</body>
</html>