index.php
<?php
// Connect to the MySQL database
include "storescripts/connect_to_mysql.php";
// This block grabs the whole list for viewing
$dynamicList = "";
$sql = mysql_query("SELECT * FROM products ORDER BY date_added DESC LIMIT 6");
$productCount = mysql_num_rows($sql); // count the output amount
if ($productCount > 0) {
while($row = mysql_fetch_array($sql)){
$id = $row["id"];
$product_name = $row["product_name"];
$price = $row["price"];
$date_added = strftime("%b %d, %Y", strtotime($row["date_added"]));
$dynamicList .= '<table width="327" border="1">
<tr>
<td width="92"><a href="product.php?"><img
src="inventory_images/' . $id . '.jpg" alt="' . $product_name . '"
width="131" height="131" border="1" /></a></td>
<td width="219" valign="top"><p>' . $product_name . '</p>
<p>Rs ' . $price . ' </p>
<p><a href="product.php?id=' . $id . '">View Product:</a></p></td>
</tr>
</table>';
}
} else {
$dynamicList = "You have no products listed in your store yet";
}
?>
product.php
<?php
if (isset($_GET['id'])) {
// Connect to the MySQL database
include "storescripts/connect_to_mysql.php";
$id = preg_replace('#[^0-9]#i', '', $_GET['id']);
//$id = $_GET['id'];
$sql = mysql_query("SELECT * FROM products WHERE id='$id' LIMIT 1");
$productCount = mysql_num_rows($sql); // count the output amount
if ($productCount > 0)
{
// get all the product details
while($row = mysql_fetch_array($sql)){
$product_name = $row["product_name"];
$price = $row["price"];
$details = $row["details"];
$category = $row["category"];
$subcategory = $row["subcategory"];
$date_added = strftime("%b %d, %Y", strtotime($row["date_added"]));
}
} else
{
echo "That item does not exist.";
exit();
}
} else {
echo "Data to render this page is missing.";
exit();
}
mysql_close();
?>
When i click on the image in index.php i get an error:
Please help