0

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?

<?php
// 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' " ;
$result=mysql_query($sql,$conn);
if (mysql_num_rows ($result)>0)
{
$row = @mysql_fetch_array ($result);
$img_type = $row["image_type"];
$img=$row["image"];
header ("Content-type: $img_type");
print $img;
}
?>


any help will be appreciated

tristan

3
Contributors
3
Replies
4
Views
11 Years
Discussion Span
Last Post by pc2forum
0

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?

0

hi,

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

thanks for your help anyway!

tristan

0

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');

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.