I am trying to dispaly images from MySQL databse without showing the actual file name in HTML page. I have two pages index.php and view.php. View.php actually the one that displays the image, but its called from index.php file. The images should be shown by it's id but when the page loads image is not displayed. CAn somebody help me to find an error in my code? Below are index.php and view.php.
index.php:
<!DOCTYPE HTML PUBLIC
"-//W3C//DTD HTML 4.0 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<head>
<title>Test</title>
</head>
<body bgcolor="white">
<?php
/
db.inc stores some common functions to access MySQL DBMS.
/
include 'db.inc';
$query = "SELECT product_id, category_id, item_number, item_name, image FROM products";
// Connect to the MySQL DBMS
if (!($connection = @ mysql_pconnect($hostName,
$username,
$password)))
showerror();
if (!mysql_select_db("catalog", $connection))
showerror();
// Run the query on the DBMS
if (!($result = @ mysql_query ($query, $connection)))
showerror();
?>
<h1>Image database</h1>
<h3>Click <a href="insert.php">here</a> to upload an image.</h3>
<?php
require 'disclaimer';
if ($row = @ mysql_fetch_array($result))
{
?>
<table>
<col span="1" align="right">
<tr>
<th>Item Number</th>
<th>Item Name</th>
<th>Image</th>
</tr>
<?php
do
{
?>
<tr>
<td><?php echo "{$row["item_number"]}";?></td>
<td><?php echo "{$row["item_name"]}";?></td>
<td><?php echo "<img src=\"view.php?file={$row["product_id"]}\">";?></td>
</tr>
<?php
} while ($row = @ mysql_fetch_array($result));
?>
</table>
<?php
} // if mysql_fetch_array()
else
echo "<h3>There are no images to display</h3>\n";
?>
</body>
view.php:
<?php
/
db.inc stores some common functions to access MySQL DBMS.
/
include 'db.inc';
$file = clean($file, 4);
if (empty($file))
exit;
// Connect to the MySQL DBMS
if (!($connection = @ mysql_pconnect($hostName,
$username,
$password)))
showerror();
if (!mysql_select_db("catalog", $connection))
showerror();
$query = "SELECT image FROM products
WHERE product_id = $file";
// Run the query on the DBMS
if (!($result = @ mysql_query ($query,$connection)))
showerror();
$data = @ mysql_fetch_array($result);
if (!empty($data["image"]))
{
// Output the MIME header
//header("Content-Type: {$data["mimeType"]}");
// Output the image
echo $data["image"];
}
?>