Page 1 of 1

Retreiving images from database

Posted: Mon Apr 13, 2009 6:44 am
by gleb
This is my first attempt at retrieving an image from a database

Code: Select all

<?
header("Content-type: image/jpeg");
mysql_connect("localhost","root","xxxxx"); 
mysql_select_db("test");
$mysql ="SELECT imgdata".
    "FROM pix ".
    "WHERE pid = 14  "; 
if ($row = mysql_fetch_assoc($mysql)) {
        $bytes = $row[imgdata];}
print $bytes;
?>
It prints the address of the page i.e. http://localhost/index.php
It makes the page: title index.php (JPEG image)

Can anyone explain what is going on?

Re: Retreiving images from database

Posted: Mon Apr 13, 2009 10:38 am
by Christopher
Is there data in $bytes ?

Re: Retreiving images from database

Posted: Mon Apr 13, 2009 10:54 am
by gleb
Only what's put there by $bytes = $row[imgdata];

Re: Retreiving images from database

Posted: Mon Apr 13, 2009 11:13 am
by n00b Saibot
I think you forgot to do a mysql_query() first....

Code: Select all

 
$mysql = "SELECT imgdata".
              "FROM pix ".
              "WHERE pid = 14  "; 
$result = mysql_query($mysql);
if ($row = mysql_fetch_assoc($result)) {
        $bytes = $row[imgdata];
}
print $bytes;