gpt4 book ai didi

php - fetch_assoc() 错误

转载 作者:行者123 更新时间:2023-11-29 21:52:16 26 4
gpt4 key购买 nike

我收到一条错误,指出第 23 行的 Call to a member function fetch_array() on boolean。第23行由这行代码组成

$row = $query->fetch_assoc();

这是整个区 block

if(!filter_has_var(INPUT_GET, 'id')) {
echo "Error: book id was not found.";
require_once ('includes/footer.php');
exit();
}
$book_id = filter_input(INPUT_GET, 'id', FILTER_SANITIZE_NUMBER_INT);

$sql = "SELECT * FROM books WHERE book_id=" . $book_id;

$query = $conn->query($sql);

$row = $query->fetch_assoc();

最佳答案

添加这个

$query = $conn->query($sql) or trigger_error($mysqli->error."[$sql]");
if ($query->num_rows > 0) {
while($row = $query->fetch_assoc()) {

}
} else {
echo "0 results";
}

Always check for errors when running a query.

关于php - fetch_assoc() 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33515178/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com