How do I retrieve Image in MYSQL using PHP?
I am currently creating an online shopping cart. In my database(test) I have a table images where all image are stored. Now my problem is that, when the moment I retrieve them, all the features in my database will displayed in my page (Something that I can't understand) not the real picture.
Could anyone can give me idea how to do it ? I Have my code below. Am I using the right Code ?? If it contains any Error, could you explain that to me? Thanks !
<?php
$username = "myusername";
$password = "mypassword";
$host = "myhost";
$database = "test";
@mysql_connect($host,$username,$password) or die ("Cannot connect to database:" .mysql_error());
@mysql_select_db($database) or die ("Unable to select database:" .mysql_error());
$id = $_GET['id'];
if(!isset($id) || empty($id))
{
die ("Please select your image");
}
else
{
$query = mysql_query("SELECT * FROM images WHERE id = '".$id."'");
$row = mysql_fetch_array($query);
$content =$row['data'];
header('Content-type: image/jpg');
echo $content;
}
?>