-------编辑-------
嗨,大家好,看到你为我解决了这个问题,我认为这将是一个好主意,再次解决同样的问题,但在不同的页面。我无法看到图像。为什么我的图像不显示?
<?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>
这是一个页面,管理员可以从一个表中的一行编辑产品。 由于某种原因,图像没有显示出来。
感谢您的任何建议。
------编辑在这里结束--------
我还是不能让我的PHP图像即使在之后的图像上传到数据库中正确的方法后才会显示。下面的代码是用于显示图像:
<form name="form1">
<input type="hidden" name="productid" />
<input type="hidden" name="command" />
</form>
<table border="0" cellpadding="2px" width="600px">
<?
$result=mysql_query("select * from products");
while($row=mysql_fetch_array($result)){
?>
<tr>
<td><?php '<img src="getImage.php?id=' . $row['serial'] .'"/>'
?>
</td>
<td> <b><a href="products.php?product_id=<?=$row['serial']?>"><?=$row['name']?></a></b><br />
<?=$row['description']?><br />
Price:<big style="color:green">
£<?=$row['price']?></big><br /><br />
<input type="button" value="Add to Cart" onclick="addtocart(<?=$row['serial']?>)" />
</td>
</tr>
<tr><td colspan="2"><hr size="1" /></td>
<? } ?>
</table>
的getImage.php
看起来是这样的:
...
$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'];
?>
只有名称,描述和价格显示在网页上了。我的MySQL表看起来像这样:
- 串行
- 名
- 描述
- 价格
- 图片(BLOB)
是作为Blob存储的图像?还应该在输出图像时设置标题,另外您应该修复sql注入。 –
是的,它被存储为一个blob ...你是什么意思设置标题? – Jahed