-5

I'm trying to display image from the database. But nothing is going to display. My code is as below: In the photo database, I have made one table named:photo inside that table there is two field id and photo. Id is auto increment. in photo .image location is saved.

<?php
$con = mysql_connect("localhost","root","");
$db = mysql_select_db("photo",$con);

$sql_image = "select * from photo";
$sql_select =  mysql_query($sql_image);

while($data = mysql_fetch_array($sql_select)) {
    echo '<img src="/images/'.$data->photo.'"/>';
}
?>
EM-Creations
  • 3,959
  • 3
  • 38
  • 55
user2028580
  • 29
  • 1
  • 3
  • 2
    You are using [an **obsolete** database API](http://stackoverflow.com/q/12859942/19068) and should use a [modern replacement](http://php.net/manual/en/mysqlinfo.api.choosing.php). – Quentin Feb 06 '13 at 11:06
  • So what output do you get? What output do you expect? Are you getting real URLs in the output? What do you get if you request them (404? 500? 403?)? – Quentin Feb 06 '13 at 11:06

3 Answers3

4

mysql_fetch_array returns an array, not an object. Use $data['photo'] to access it.

Niet the Dark Absol
  • 311,322
  • 76
  • 447
  • 566
2

Replace echo '<img src="/images/'.$data->photo.'"/>';

To echo '<img src="/images/".$data[photo]."/>';

Devang Rathod
  • 6,434
  • 2
  • 22
  • 31
0

Instead of

while($data = mysql_fetch_array($sql_select)) {
        echo '<img src="/images/'.$data->photo.'"/>';
    }

Try this:

while($data = mysql_fetch_array($sql_select)) {
    echo '<img src="/images/'.$data['photo'].'"/>';
}
Sankalp Mishra
  • 5,766
  • 4
  • 28
  • 58