0

I got a problem while displaying the images from MySQL Database. When I load the page, only the empty image element is loaded but not the actual image coming from database. I think that php code is not correct.

<?php 

 //connection do db
require_once __DIR__.'/connect.php';

try{
     $stmt = $db->prepare('SELECT * FROM pictures');
     $stmt->execute();
     if($stmt->rowCount()>0)
     {
         while($row=$stmt->fetchColumn())
         {
             extract($row);
;         }
     } 

}catch (PDOEXception $ex){
    echo $ex;
}
?>
<img src="images/<?php echo $row['path']?>"> 
4
  • 1
    Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. Commented May 15, 2019 at 21:51
  • It sounds like the image is not coming from the DB, just the path to the image. If you view source on the, does value of the img element's src attribute look correct? Is it just images/ or is there an actual path to an image file there? If it looks correct, then are you sure that is the correct URL to the image on your web server? Could you provide some sample output from the html page and also a full URL to an image that works when requested directly? Commented May 16, 2019 at 0:10
  • Aren't you missing a ; after the PHP line? <?php echo $row['path'];?> Commented May 16, 2019 at 0:16
  • img tag is outside while loop (sidenode: don't post code in lines with ``` - it's not displayed) Commented May 16, 2019 at 7:33

1 Answer 1

1

You have to create <img> tags in while loop. Try:

while($row=$stmt->fetchColumn())
{
    extract($row);
    echo '<img src="images/'.$row['path'].'">'; 
}
Sign up to request clarification or add additional context in comments.

Comments

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.