Page 1 of 1

Not able to display the image stored in database

Posted: Mon Aug 03, 2009 10:26 pm
by jacob_abraham
Hi,
I am trying to retrieve a image from MySQL database and display it on the browser using PHP. The SQL query is fine I am able to retrieve the image from the database but when I try to display it on the screen the image does not show up. Below is the two php files that I am using for displaying the image. Can someone please let me know what am I doing incorrect here...

File 1 - Containing the img tag

Code: Select all

 
<?php include("header.php"); ?>
<div id="mainContent">
<div class="pageHeader">
    <h2><font color="black"> Image </font></h2>
</div>
<div>
<?php
    $imageName = $_GET['imageName'];
    echo '<img src="retrieve_Images.php'"/>';
?>
 
</div>
<?php include("footer.php"); ?>
 
File 2 - Contains the code to query the database

Code: Select all

 
<?php
    include("conf.php");
    $conn = open_connection();
    $imageName = 'nature';
    $query = "SELECT user_image.image FROM user_image WHERE user_image.image_name='$imageName'";
    $retrieve_Image_Result = mysql_query($query) or die(mysql_error()); //mysql query
    if($retrieve_Image_Result){
            header("Content-type: image/jpeg");
                    echo mysql_result($retrieve_Image_Result, 0);
    }
             close_connection($conn);
 
?>
 

Re: Not able to display the image stored in database

Posted: Tue Aug 04, 2009 1:53 am
by dave1909
see if this works

Code: Select all

<?php include("header.php"); 
include("retrieve_Images.php");
?>
 <div id="mainContent">
<div class="pageHeader">
     <h2><font color="black"> Image </font></h2>
 </div>
 <div>
 <?php
     $imageName = $_GET['imageName'];
     echo '<img src="$retrieve_Image_Result"/>';
 ?>
  
 </div>
 <?php include("footer.php"); ?>