0

So I am trying to display a BLOB data from a database using the PHP code below, but it doesn't load, in the place of the picture I can only see the question mark (absence). What did I do wrong? I'm new to PHP btw.

<?php
    $query = "SELECT * FROM `blog_posts` LIMIT 0, 30 ";
    $result = mysqli_query($db, $query);
    while($row = mysqli_fetch_assoc($result)) {
        echo "<article>"; 
        echo    "<header>".$row["title"]."</header>"; 
        echo    "<div class='post-content'>";   
        echo        "<div class='post-image'><img src='data:image/jpeg;base64,".base64_encode($row["picture"])." width='290' height='290'></div>"; 
        echo        "<div class='post-text'>".$row["body"]."</div>"; 
        echo    "</div>"; 
        echo    "<div class='post-footer'>".$row["likes_number"]."  likes ".$row["comments_number"]."  comments"; 
        echo    "</div>";
        echo "</article>";
    }
?>
2
  • Have you checked your error logs? Commented Mar 13, 2017 at 21:47
  • How are you storing the image in the DB? If you look at your page html source, what do you see? Commented Mar 13, 2017 at 21:48

1 Answer 1

1

I think the problem is that you are missing a closing single quote after the src of the tag

add ' after src='data:image/jpeg;base64,".base64_encode($row["picture"])." or try this src="data:image/jpeg;base64,'.base64_encode($row['picture']).'"

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

2 Comments

Yes, I just noticed that, but thank you! It works now.
Always happy to help

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.