-1

I have a getimage.php containing

<?php
$id = $_GET['id'];
// do some validation here to ensure id is safe

 $link = mysql_connect("localhost", "user", "password");
 mysql_select_db("database");
 $sql = "SELECT photo FROM property_photo WHERE id=$id";
 $result = mysql_query("$sql");
 $row = mysql_fetch_assoc($result);
 mysql_close($link);

 header("Content-type: image/jpeg");
 echo $row['property_photo'];
 ?>

and my index.php

<div class="bloco">  <img src="getImage.php?id=1" ?>
<div>Description</div>
</div>
<div class="insert"></div>
</div>

i can't see the photo, It won't display or it displays as a blank box with a blue question mark.

Martin
  • 22,212
  • 11
  • 70
  • 132
  • Possible duplicate of [I can't retrieve Image from my database](http://stackoverflow.com/questions/12937704/i-cant-retrieve-image-from-my-database) – arc Jan 25 '16 at 10:02
  • beside the possibile sql injection, have you check the `getImage.php?id=1` page? is it contains only the contents of the image, or also some php errors at the top? – Federkun Jan 25 '16 at 10:05
  • Do not paste your username and password details into public places such as stack overflow questions. – Martin Jan 25 '16 at 10:07
  • Please note that the `mysql_*` methods are deprecated and completely removed in PHP7 (meaning your code will fail if you upgrade PHP). Use PDO or MySQLi instead. Your code is also open to SQL injections (use prepared statements and bind your variables instead of pasting variables in the middle of a query). – h2ooooooo Jan 25 '16 at 10:08

2 Answers2

3

In your query you are selecting the field 'photo' but when you come to echo the field you actually echo the name of the table:

echo $row['property_photo'];

So I believe your actually getting a hidden fatal error instead of the image saying - unknown index 'property_photo'

try

echo $row['photo'];

instead.

Horaland
  • 857
  • 8
  • 14
0

use ob_clean() before header, it may solves your problem

Mostafa M
  • 1,000
  • 8
  • 7