Hi guys,
I have written a simple code here that should be able to display the image "tulips" from my database?
But it does not work, wondering what is wrong with the code?

// database connection
$host = "localhost";
$user = "user";
$pass = "password";
$db = "imagedb";
$table= "image";

$conn = mysql_connect($host, $user, $pass)
OR DIE (mysql_error());
@mysql_select_db ($db, $conn) OR DIE (mysql_error());

$sql="SELECT * FROM image WHERE image_name= 'tulips' " ;
if (mysql_num_rows ($result)>0)
$row = @mysql_fetch_array ($result);
$img_type = $row["image_type"];
header ("Content-type: $img_type");
print $img;

any help will be appreciated


Help us out a bit - what does 'it doesn't work' mean? Are you getting an error, blank page, wrong image? Also, what values are held in the variable $img_type? Do they match with registered content types?


i have solved the problem, its was a small mistakes, the name should be "tulips.jpeg" instead of "tulips"

thanks for your help anyway!


is $img is the image or its just an name of the image file . if its the name file or url of the file then simply put $img in header
ie header($img)

if its an image then dont use header('content-type:$img_type');