2015-11-04 60 views
0

我得到這一呼籲說一個成員函數fetch_array布爾線錯誤()23. 線23由該行代碼FETCH_ASSOC()錯誤

$row = $query->fetch_assoc(); 

這裏是整個塊

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(); 
+1

echo'$ sql =「SELECT * FROM books WHERE book_id =」。 $ book_id; '檢查你的查詢 – Saty

回答

0

添加此

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

    } 
} else { 
    echo "0 results"; 
} 

運行查詢時總是檢查錯誤。

+0

@downvoter你可以指定原因 –

+0

後添加此通知說,我有一個錯誤在我的SQL語法,我沒有看到一個 –

+0

Chnage你的SQL像'$ sql =「SELECT * FROM書WHERE book_id ='$ book_id'「;' –

相關問題