Consider the following code
<?php
$username = "root";
$password = "";
$host = "localhost";
$database = "binaries";
@mysql_connect($host, $username, $password) or die("Can not connect to database: ".mysql_error());
@mysql_select_db($database) or die("Can not select the database: ".mysql_error());
$id = 5;
if(!isset($id) || empty($id)){
die("Please select your image!");
}else{
$query = mysql_query("SELECT * FROM tbl_images WHERE id='".$id."'");
$row = mysql_fetch_array($query);
$content = $row['imag'];
header('Content-type: image/jpg');
echo '<table><tr><td height="700" width="700">';// Line X
print $content;
echo '</td></tr></table>';//Line Y
}
?>
When I comment the lines X and Y the image gets displayed, otherwise not.What could be the possible reason?
EDIT: After following Matt's advice.
show.php
echo '<table><tr><td>
<img src="image.php"/>
</td></tr></table>';
image.php
$query = mysql_query("SELECT * FROM tbl_images WHERE id='".$id."'");
$row = mysql_fetch_array($query);
$content = $row['imag'];
header('Content-type: image/jpg');
print $content;
Even after doing this I am not getting the expected result.
EDIT: code of 'image.php' :
<?php
$username = "root";
$password = "";
$host = "localhost";
$database = "binaries";
@mysql_connect($host, $username, $password) or die("Can not connect to database: ".mysql_error());
@mysql_select_db($database) or die("Can not select the database: ".mysql_error());
$query = mysql_query("SELECT * FROM tbl_images WHERE id=5");
$row = mysql_fetch_array($query);
$content = $row['imag'];
header('Content-type: image/jpg');
echo $content;
?>