0
當我管理它插入到我的分貝數據庫後,我試圖從MySQL顯示一個BLOB。從mySQL顯示BLOB與PHP
這是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'];
?>
這裏的HTML:
<img src="getImage.php?id=1" width="200" height="200" />
這是我的數據庫的內容:
不幸的是開發工具拋出一個內部服務器500錯誤。 Browser-Output:
有人可以告訴我我做錯了什麼嗎?
非常感謝!
首先,你的代碼很容易受到SQL注入。你不應該使用不推薦使用的'mysql_ *'方法。改用PDO或mysqli的參數化查詢。其次,你的SQL語句最後有太多的'''字符。 – Chris
謝謝你的提示 - 刪除雙'沒有解決問題。 –
這聽起來像你需要[打開錯誤報告](http://stackoverflow.com/questions/845021/how-to-get-useful-error-messages-in-php),並找出問題所在。 – Chris