0

I have been trying to echo images from my database using PHP. I have tried various solutions on the forum with no success. I am just getting a blank image as an output.

while($rows=mysqli_fetch_assoc($getquery))
{
    $id=$rows['id'];
    $LastName=$rows['LastName'];
    $FirstName=$rows['FirstName'];
    $Year=$rows['Year'];
    $Press=$rows['Press'];
    $Description=$rows['Description'];
    $Title=$rows['Title'];
    $image=$rows['image'];


    echo '<div class = "paragraph">' . $LastName . '<br/>'. $FirstName . '<br/>' . $Year . '<br/>' .  $Press . '<br/>' . $Title . '<br/>'. $Description . "<img src='image/".$row['image']."' />" . '</div>' ;
}

2 Answers2

2

You're echoing the image as $row['image'], but the only prior references to the image are $rows['image'] (note the s) and $image. Update the echo statement to use either of these and not $row['image'].

Edit: This will not fully fix your issue. As noted in a comment to your question, you will need to do some finagling to actually display the image as demonstrated here.

Community
  • 1
  • 1
cteski
  • 487
  • 3
  • 12
  • 17
0
while($rows=mysqli_fetch_assoc($getquery)){
    $id=$rows['id'];

    /*
       assuming the `image` directory is relative to the root
       and not the directory from which the script runs then
       a leading slash might be the issue.
    */
    echo "
    <div id='{$id}' class='paragraph'>
        {$rows['LastName']}<br/>
        {$rows['FirstName']}<br/>
        {$rows['Year']}<br/>
        {$rows['Press']}<br/>
        {$rows['Title']}<br/>
        {$rows['Description']}
        <!--<img src='/image/{$row['image']}' />-->
        <img src='data:image/jpeg;base64, {$rows['image']}' alt='' title='' />
    </div>";
}

If you store the mimetype of the image when you save it to the db then you would substitute the proper mime/content type in above ~ ie: image/png, image/gif etc so that might then become something like:

<img src='data:{$rows['mimetype']};base64, {$rows['image']}' alt='' title='' />
Professor Abronsius
  • 33,063
  • 5
  • 32
  • 46