Not able to display the image stored in database

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
jacob_abraham
Forum Newbie
Posts: 1
Joined: Mon Aug 03, 2009 10:10 pm

Not able to display the image stored in database

Post 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);
 
?>
 
dave1909
Forum Newbie
Posts: 22
Joined: Sat Jul 25, 2009 8:56 pm

Re: Not able to display the image stored in database

Post 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"); ?>
Post Reply