Image retriving

0 Eng Iroqious Saviour · March 5, 2015
I wanted to retrieve my images from database, but the image caption only appears and the real image doesn't appear yet they successfully stored in the database., below is my code
<?php
include('config.php');
$result = mysql_query("SELECT * FROM photos");
while($row = mysql_fetch_array($result))
{
echo '<div id="imagelist">';
echo '<p><img src="'.$row['location'].'"></p>';
echo '<p id="caption">'.$row['caption'].' </p>';
echo '</div>';
}
?>


Post a Reply

Replies

Oldest  Newest  Rating
0 Mohamad Mirohamadi · March 5, 2015
its is because you are using real path instead of relative path , can you put one of your table records for better inspection?
0 Ibrahim Tuzlak · March 6, 2015
Yeap, as Mohamad said.

The current image location that <img's src gets might be something like:
localhost/wamp/www/.../image.png

which doesn't make sense.
You may want to inspect the img element inside your browser and it'll hopefully show 404 to the image location. That way, you can rewrite the way image links are stored inside `location` in your DB table.
0 Michael Chimezie · March 6, 2015
you have to check how the img path is stored in the location column in your database, then from there you will know how to point the correct path in the src attr. As Mohamad said above, pasting a sample of your table records will be more helpful. And also stop using mysql, it has be depreciated. Use mysqli or PDO instead.
  • 1

PHP

107,048 followers
About

Server-side, HTML embedded scripting language used to create dynamic Web pages.

Links
Moderators