Php 为什么不是';我的形象没有出现吗?

Php 为什么不是';我的形象没有出现吗?,php,mysql,Php,Mysql,-------编辑------- 嗨,伙计们,看到你们为我解决了这个问题,我想再解决一次同样的问题,但换一个页面是个好主意。我无法让图像显示出来 <?php $id = $_GET['product_id']; $query = mysql_query("SELECT * FROM products WHERE serial = '$id'") or die(mysql_error()); while($info = mysql_fetch_array($query)) {

-------编辑-------
嗨,伙计们,看到你们为我解决了这个问题,我想再解决一次同样的问题,但换一个页面是个好主意。我无法让图像显示出来

    <?php
$id = $_GET['product_id'];
$query = mysql_query("SELECT * FROM products WHERE serial = '$id'")
or die(mysql_error());  

while($info = mysql_fetch_array($query)) {
echo "";

$name = $info['name'];
$description = $info['description'];
$price = $info['price'];
$picture = $info['picture'];

}
?>

<form action="editsuccess.php?product_id=<?php echo $id; ?>" method="post">

Product ID:<br/>
<input type="text" value="<?php echo $id;?>" name="product_id" disabled/>

<br/>

Name:<br/>
<input type="text" value="<?php echo $name;?>" name="name"/>

<br/>

Description:<br/>
<input type="text" value="<?php echo $description;?>" name="description"/>

<br/>

Price:<br/>
<input type="text" value="<?php echo $price;?>" name="price"/>

<br/>

Picture:<br/>
<? echo'<img src="../getImage.php?id=' . $info['serial'] .'"/>'?> 

</br>

<input type="submit" value="Update Product"/>

</form>
网页上只显示名称、说明和价格。我的MySQL表如下所示:

...
$link = mysql_connect($host, $user, $passwd);
mysql_select_db($dbName);
$query = 'SELECT picture FROM products WHERE serial="' . $_GET['id'] . '"';
$result = mysql_query($query,$link);
$row = mysql_fetch_assoc($result);
echo $row['picture'];
?>
  • 连载
  • 名字
  • 描述
  • 价格
  • 图片(斑点)

在回显图像数据之前,您没有设置正确的
内容类型
标题

您还必须转义
$\u GET['id']
参数

// Escape $id
$id = mysql_real_escape_string($_GET['id']);   

$link = mysql_connect($host, $user, $passwd);
mysql_select_db($dbName);

// Use the escaped $id
$query = "SELECT picture FROM products WHERE serial='$id'";
$result = mysql_query($query,$link);

if ($result) {
  $row = mysql_fetch_assoc($result);

  // Set the Content-type
  // This assumes image/jpeg. If you have different image types,
  // you'll need logic to supply the correct MIME type
  // image/jpeg image/png image/gif, etc
  header("Content-type: image/jpeg");
  echo $row['picture'];
}
?>
在主脚本中,看起来您只是缺少了一个
echo

        <td><?php '<img src="getImage.php?id=' . $row['serial'] .'"/>'
        // Should be
        <td><?php echo '<img src="getImage.php?id=' . $row['serial'] .'"/>'
        // ------^^^^^^

hi,我现在在getImage.php页面上看到一个错误,上面写着:“*****.com/music/getImage.php”图像无法显示,因为它包含错误。看起来您没有提供
id
。浏览至
http://www.yourdomain.com/musics/getImage.php?id=somevalidid
这表示1)没有为查询返回任何记录,2)表中的数据已损坏,3)为图像设置了错误的内容类型标题,或者4)您的脚本将文本与图像数据一起输出,从而使浏览器认为图像已损坏。另外,请检查图像是否实际存储在数据库中&不仅仅是图像存储在数据库中的路径,我想不出还有任何其他错误。我是php新手,所以我真的不知道如何处理这个问题…还有其他帮助吗?图像是否存储为blob?当输出为图像时,还应设置标题,另外还应修复sql注入。是的,它存储为blob…设置标题是什么意思?
        <td><?php '<img src="getImage.php?id=' . $row['serial'] .'"/>'
        // Should be
        <td><?php echo '<img src="getImage.php?id=' . $row['serial'] .'"/>'
        // ------^^^^^^