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

Recommended Answers

All 3 Replies

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?

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

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.