0

After I managed it to insert blobs into my db I'm trying to Display a BLOB from MySQL.

This is the getImage.php:

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

  $link = mysql_connect("localhost", "root", "root");
  mysql_select_db("user_auth_tutorial");
  $sql = "SELECT image FROM testblob WHERE image_id='$id''";
  $result = mysql_query("$sql");
  $row = mysql_fetch_assoc($result);
  mysql_close($link);
  header("Content-type: image/jpeg");
  echo $row['image'];
?>

Here the HTML:

<img src="getImage.php?id=1" width="200" height="200" />

This is the content of my db: table testblob

Unfortunately Dev-Tools throw an internal server 500 Error. Browser-Output: Screenshot

Can anybody tell me what I do wrong?

Thank you so much!

Musa
  • 96,336
  • 17
  • 118
  • 137
Fabi Cho
  • 33
  • 3
  • 1
    First of all, your code is vulnerable to SQL injection. You shouldn't use the deprecated `mysql_*` methods. Use parameterized queries with PDO or mysqli instead. Secondly, your SQL statement has too many `'` characters at the end. – Chris Apr 28 '16 at 21:19
  • Thank you for the hint - removing the double ' did not solve the problem. – Fabi Cho Apr 28 '16 at 21:32
  • It sounds like you need to [turn on error reporting](http://stackoverflow.com/questions/845021/how-to-get-useful-error-messages-in-php) and find out what the problem is. – Chris Apr 28 '16 at 21:33

1 Answers1

-1

try this

echo '<img src="data:image/jpeg;base64,'.base64_encode($row['image']).'"/>';
Rafael Mota
  • 127
  • 4