0

Possible Duplicate:
How can I store and retrieve images from a MySQL database using PHP?

I have uploaded my images perfectly in the blob field but i am not able to display the image i used the following code but its not working:

<?php

$username = "root";
$password = "";
$host = "localhost";
$database = "bakery";

@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 = 3 ;

if($id==3){


$query = mysql_query("SELECT img FROM pic WHERE Desc='".$id."'");
$row = mysql_fetch_array($query);
$content = $row['image'];

header('Content-type: image/jpg');
echo $content;

}

?>
Community
  • 1
  • 1
Manikandan Thangaraj
  • 1,594
  • 8
  • 24
  • 44
  • 1
    the linked question has an excellent answer to your question BTW. – Johan Aug 04 '11 at 08:56
  • And BTW you don't need this syntax: `("SELECT img FROM pic WHERE Desc='".$id."'");`, this will also work: `("SELECT img FROM pic WHERE Desc='$id'");` Much simpler IMHO. – Johan Aug 04 '11 at 08:58
  • @Johan: it's much simpler but much dirtier ... figure out what will you see in a code highlighting application ... – Mihai Iorga Aug 04 '11 at 09:18
  • @Mihai, I get dizzy from all those extra `.` and `"` the simpler syntax looks much cleaner to me, a matter of taste I guess. – Johan Aug 04 '11 at 09:26
  • @Johan yes :), but believe me, 'programmers' intend not to use the correct syntax anymore. Which is bad because if you need to correct or change something after them you will really get dizzy. From my opinion I would change this: '$var' => '".$var."', $_POST[var] => $_POST['var'], SELECT img => SELECT ` img` as it should be. – Mihai Iorga Aug 04 '11 at 11:42
  • @Mihai, `as it should be` I disagree, it's purely a matter of taste. – Johan Aug 04 '11 at 11:46

0 Answers0