-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
  • 4,195
  • 4
  • 40
  • 56
user2028580
  • 27
  • 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
  • 320,036
  • 81
  • 464
  • 592
2

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

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

Devang Rathod
  • 6,650
  • 2
  • 23
  • 32
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'].'"/>';
}
Engineer
  • 5,911
  • 4
  • 31
  • 58