displaying image from MySQL DB using HTML/PHP



I am having some difficulty getting an image to display on a php that
I have added to MySQL DB.

Here is what I have tried so far....

in the MySQL DB I have a table called image_holder and the fields are
id,mimename,filecontents...filecontents field is set to a type of blob
using PHPMyAdmin and I have uploaded the image in MySQL.

In the PHP code I have:

[php]
<?php
$dbhost = 'hostaddress';
$dbuser = 'username';
$dbpass = 'password;
$dbcnx = @mysql_connect($dbhost,$dbuser,$dbpass);

if (!$dbcnx)
{
echo( "connection to database server failed!");
exit();
}
if (! @mysql_select_db("image_holder") )
{
echo( "Image Database Not Available!" );
exit();
}

$img = $_REQUEST["img"];

$result = @mysql_query("SELECT * FROM images WHERE id=" . $img . "");

if (!$result)
{
echo("Error performing query: " . mysql_error() . "");
exit();
}
while ( $row = @mysql_fetch_array($result) )
{
$imgid = $row["id"];
$encodeddata = $row["mimetype"];
$title = $row['filecontents'];
}

?>

and in the HTML code

<center><img src="image.php?img=1" width="200" border="1" alt=""></center>

I am probably way off base, so need some help!


--
::Bruce::
.



Relevant Pages

  • Re: mysql apache - page never finish loading
    ... my PHP pages don't want to finish loading. ... echo 'a'; ... Opera and IE behaves somewhat differently. ... All this happens whenver I connect to mysql. ...
    (comp.lang.php)
  • Re: I am totally stumped..with this on..LOAD_FILE Mysql+PHP= FSCK!!
    ... What I am trying to do is to upload files and stuff them in a mysql database. ... I copied the temporary file to somewhere else, and then handed it to MySQL..THAT WORKED.. ... Is there a way to force a close on the file..maybe that's the problem Mysql is opening a file that is not flushed to disk maybe? ... I gew the feeling its maintaining its own picture of file objects, and doesn't actually flush to the disk unless you do a copy or close php.. ...
    (comp.lang.php)
  • Re: I am totally stumped..with this on..LOAD_FILE Mysql+PHP= FSCK!!
    ... What I am trying to do is to upload files and stuff them in a mysql database. ... I copied the temporary file to somewhere else, and then handed it to MySQL..THAT WORKED.. ... Is there a way to force a close on the file..maybe that's the problem Mysql is opening a file that is not flushed to disk maybe? ... I gew the feeling its maintaining its own picture of file objects, and doesn't actually flush to the disk unless you do a copy or close php.. ...
    (comp.lang.php)
  • Re: [PHP] Re: Sorry forgot to include the code for my last message - Mike Francis
    ... I have the usual permissions on the database server which is accessible via ... I have the MyODBC driver installed and configured just in case PHP is ... echo 'Unable to connect to the '. ... exit('Unable to locate the joke '. ...
    (php.general)
  • Re: com_dotnet
    ... And if MySQL isn't installed, the DLL won't load and phpinfowill show MySQL support isn't enabled. ... The MySQL interface is NOT compiled into PHP on the distributed Windows binaries - or you'd never be able to run PHP unless you had MySQL installed. ... *SOME* extensions are protocols, some are functional resources, and some are just type libraries. ... If you're going to compile the extension into PHP itself, the libraries must be available at compile time, and when you run PHP, or PHP won't load. ...
    (comp.lang.php)