mysqli准备select查询没有结果

uinbv5nw  于 2021-08-09  发布在  Java
关注(0)|答案(0)|浏览(122)

经过几个小时的努力,我终于找到了答案。查询既不返回错误,也不显示数据库中存在的任何数据。提交带有参考号的表单时,它应该显示与之匹配的记录。我错过了什么很愚蠢的事吗?!

$servername = "xxx";
$username = "xxxx";
$password = "xxx";
$dbname = "xxx";

// Create connection
$conn = mysqli_connect($servername, $username, $password, $dbname);
// Check connection
if (!$conn) {
    die("Connection failed: " . mysqli_connect_error());
}
$ref = trim(($_POST['ref']));

$count=1;

$sel_query="SELECT ref, sname, fname, B1 FROM Enrol where ref =?";
$stmt = $conn->prepare($sel_query); 

$stmt->bind_param("s", $ref);
$stmt->execute();
$result = $stmt->get_result(); // get the mysqli result
$user = $result->fetch_assoc(); // fetch data   
if($result->num_rows === 0) exit('No results!');
while($row = $result->fetch_assoc()) {  ?>

<tr>
<td><?php echo $count; ?></td>
<td><?php echo $row["ref"]; ?></td>
<td><?php echo $row["sname"]; ?></td>
<td><?php echo $row["fname"]; ?></td>
<td><?php echo $row["B1l"]; ?></td>

</tr>

<?php $count++; } ?>

</table>

</body>

<?php
$stmt->close();
?>

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题