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

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

Comments

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='' />

3 Comments

the images aren't even in a directory, they are in a database. i need them to echo from the DB.
so you have stored the base64 encoded image content and need to output that? generally the format would be something like <img src="data:image/jpeg;base64, /<BASE64_STRING>" />
yeah, that's essentially what i need. I'm checking around now for a way to accomplish this.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.