图像不会显示在mysql数据库中

时间:2014-02-20 15:04:46

标签: php html mysql

我正在尝试显示我的数据库中的图像,但它不显示。我研究并尝试了我能理解的不同代码,但它仍然没用。这是我的show image php code

<?php

$host="localhost";
$username="root"; // Mysql username 
$password=""; // Mysql password 
$db_tocode="db_tocode"; // Database name 

mysql_connect($host, $username, $password) or die("Can not connect to database:     ".mysql_error());

mysql_select_db($database) or die("Can not select the database: ".mysql_error());

$id = $_GET['id'];

$sql = "SELECT * FROM image WHERE id = '$id';";

 $result = mysql_query($sql) or die(mysql_error());  
$row = mysql_fetch_array($result);

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


?>

以下是向网站显示图片的链接。

     <img src="showimage.php?id=<?php echo $id;?">">
     <div class="text-style"></div>

提前感谢!

1 个答案:

答案 0 :(得分:0)

如果您的id列不是字符串,则应删除$id周围的句点:

$sql = "SELECT * FROM image WHERE id = $id;";

调试缺少数据的问题的一种好方法是在每次sql查询后添加一个print语句。然后,您可以将确切的语句复制并粘贴到数据库控制台,查看获得的结果以及数据的确切位置与您的预期不符。