图像不会从数据库检索到使用PHP的HTML格式 [英] image does not get retrieved from database into html form using php
本文介绍了图像不会从数据库检索到使用PHP的HTML格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Getimage.php
<?php
$ hostname =localhost;
$ username =root;
$ password =tiger;
$ b $ * $ var $ dbhandle type * /
$ dbhandle = \mysqli_connect($ hostname,$ username,$ password)
或die(无法连接到MySQL );
$ b / * @var $ select type * /
$ select = \mysqli_select_db($ dbhandle,sample)
或mysqli_error($ dbhandle);
/ * @var $ itemId type * /
$ itemId =(\filter_input(\INPUT_GET,'name'));
$ sql =从starterveg中选择img,其中itemId = $ itemId;
$ res2 = mysqli_query($ dbhandle,$ sql);
$ row = mysqli_fetch_assoc($ res2);
mysqli_close($ dbhandle);
header(Content-type:image / jpeg);
echo $ row ['img'];
?>
< body>
< img src =Getimage.php?itemId = oepsv1086alt =imageid =img1>
< / body>
>
我无法将数据库中的图像显示到html中。取而代之的是,alt消息只出现在html表单中
解决方案
在您的getimage.php中尝试
header(Content-type:image / jpeg);
stripslashes($ row ['img']);
echo $ row ['img'];
***不建议在DB中存储图像。*
编辑2 >>
$ itemId =(\filter_input( \INPUT_GET, '名称'));
这应该是
$ itemId =(\filter_input(\INPUT_GET,'itemId')); #as你正在传递itemid到get
编辑3 >>
您在查询中缺少单引号('),导致错误
应该是
$ sql =从starterveg中选择img,其中itemId ='$ itemId';
Getimage.php
<?php
$hostname="localhost";
$username="root";
$password="tiger";
/* @var $dbhandle type */
$dbhandle = \mysqli_connect($hostname, $username, $password)
or die("Unable to connect to MySQL");
/* @var $select type */
$select= \mysqli_select_db($dbhandle,"sample")
or mysqli_error($dbhandle);
/* @var $itemId type */
$itemId= (\filter_input(\INPUT_GET,'name'));
$sql="select img from starterveg where itemId=$itemId";
$res2=mysqli_query($dbhandle,$sql);
$row= mysqli_fetch_assoc($res2);
mysqli_close($dbhandle);
header("Content-type: image/jpeg");
echo $row['img'];
?>
<body>
<img src="Getimage.php?itemId=oepsv1086" alt="image" id="img1">
</body>
> I'm not able to display the image from database into the html for.Instead the alt message only appears inside the html form
解决方案
Try in your getimage.php
header("Content-type:image/jpeg");
stripslashes ($row['img']);
echo $row['img'];
***storing image in DB is not recommended.*
EDIT 2 >>
$itemId= (\filter_input(\INPUT_GET,'name'));
this should be
$itemId= (\filter_input(\INPUT_GET,'itemId')); #as you are passing itemid in get
EDIT 3>>
You were missing single quotes (') in where query , that was causing errors
it should be
$sql="select img from starterveg where itemId='$itemId'";
这篇关于图像不会从数据库检索到使用PHP的HTML格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文