Javascript 使用自动完成选择从数据库检索BLOB图像
我试图显示一个存储在数据库中的blob图像,我没有得到任何错误,但是图像没有显示,我只是得到默认的“无图像”图标。这是我的密码:Javascript 使用自动完成选择从数据库检索BLOB图像,javascript,php,database,image,xhtml,Javascript,Php,Database,Image,Xhtml,我试图显示一个存储在数据库中的blob图像,我没有得到任何错误,但是图像没有显示,我只是得到默认的“无图像”图标。这是我的密码: <script> function showEmpimg(str) { var xhttp; if (str == "") { document.getElementById("user-id").innerHTML = ""; return;
<script>
function showEmpimg(str) {
var xhttp;
if (str == "") {
document.getElementById("user-id").innerHTML = "";
return;
}
xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
document.getElementById("face").innerHTML = this.responseText;
}
};
xhttp.open("POST", "getimage.php?q="+str, true);
xhttp.send();
}
</script>
</head>
<body>
<div id="face" class="face">
</div>
<input type="text" class="form-control" id="user-id" placeholder="ID" name="emp_id" onchange="showEmpimg(this.value)" required maxlength="6" />
函数showEmpimg(str){
var-xhttp;
如果(str==“”){
document.getElementById(“用户id”).innerHTML=“”;
返回;
}
xhttp=newXMLHttpRequest();
xhttp.onreadystatechange=函数(){
if(this.readyState==4&&this.status==200){
document.getElementById(“face”).innerHTML=this.responseText;
}
};
open(“POST”,“getimage.php?q=“+str,true”);
xhttp.send();
}
以及php文件:
<?php
$db = mysqli_connect("localhost","root","test1","dar");
$sql = "SELECT emp_img FROM employees WHERE emp_id LIKE 'q'";
$sth = $db->query($sql);
$result=mysqli_fetch_array($sth);
echo '<img src="data:image/jpeg;base64,'.base64_encode( $result['emp_img'] ).'"/>';
?>
有什么想法吗?解决了:
$db = mysqli_connect("localhost","root","test1","dar");
$sql = "SELECT * FROM employees WHERE emp_id=" . intval($_GET['q']);
$sth = $db->query($sql);
$result=mysqli_fetch_array($sth);
//var_dump($result);
echo '<img class="face" src="data:image/jpeg;base64,'.base64_encode( $result['emp_img'] ).'"/>';
$db=mysqli_connect(“localhost”、“root”、“test1”、“dar”);
$sql=“从emp_id=”的员工中选择*。intval($_GET['q']);
$sth=$db->query($sql);
$result=mysqli\u fetch\u数组($sth);
//var_dump($结果);
回声';
$result['emp\u img']的内容是什么?它应该是一个BLOB.jpg文件。从数据库中。执行后检查代码时,img src显示“data:image/jpeg;base64”,但不显示其余部分。