我正在使用DB中的以下代码检索器图像以及其他属性,即全名,手机号等。但它显示的是一个空的图像框。
require 'database.php';
$MobileNo = null;
if ( !empty($_GET['MobileNo'])) {
$MobileNo = $_REQUEST['MobileNo'];
}
if ( null==$MobileNo ) {
header("Location: index.php");
} else {
$pdo = Database::connect();
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$sql = "SELECT * FROM user where MobileNo = ?";
$q = $pdo->prepare($sql);
$q->execute(array($MobileNo));
$data = $q->fetch(PDO::FETCH_ASSOC);
Database::disconnect();
}
?>
<div class="control-group">
<label class="control-label">Picture</label>
<div class="">
<label class="">
<?php
$row = $data or die("line 44 not working");
$s=$row['Picture'];
echo $row['Picture'];
echo '<img src="'.$s.'" alt="HTML5 Icon"style="width:128px;height:128px">';
?>
</label>
</div>
</div>
答案 0 :(得分:1)
在获取$row = $data or die("line 44 not working");
设置变量后需要断开连接。
if ( null==$MobileNo ) {
header("Location: index.php");
} else {
$pdo = Database::connect();
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$sql = "SELECT * FROM user where MobileNo = ?";
$q = $pdo->prepare($sql);
$q->execute(array($MobileNo));
$data = $q->fetch(PDO::FETCH_ASSOC);
$row = $data or die("line 44 not working");
$s=$row['Picture']; //This is where you make the change.
echo $row['Picture'];
Database::disconnect(); //Now disconnect
}
?>
<div class="control-group">
<label class="control-label">Picture</label>
<div class="">
<label class="">
<?php
echo '<img src="'.$s.'" alt="HTML5 Icon"style="width:128px;height:128px">';
?>
</label>
</div>
</div>