如何修复此错误以创建我的流程页面以转到我的数据库上的下一个问题:
致命错误:在第32行的C:\ wamp \ www \ quiz \ process.php中的非对象上调用成员函数fetch_assoc()
<?php
//check to see if score is set_error_handler
if (!isset($_SESSION['score'])) {
$_SESSION['score'] = 0;
}
if ($_POST) {
$number = $_POST['number'];
$selected_choice = $_POST['option'];
$next = $number++;
/*
* Get total questions
*/
$query = "SELECT * FROM questions";
//Get result
$results = $mysqli->query($query);
$total = $results->num_rows;
/*
* Get correct option
*/
$query = 'SELECT * FROM options WHERE WHERE question_no = $number AND is_correct = 1';
// Get result
$result = $mysqli->query($query);
// Get row
$row = $result->fetch_assoc();
//Set correct choice
$correct_choice = $row['id'];
//Compare
if ($correct_choice == $selected_choice) {
//Answer is correct
$_SESSION['score']++;
答案 0 :(得分:0)
检查下面的**** Changed Line ****。使用fetch_assoc而不是mysqli_fetch_assoc
/*
* Get total questions
*/
$query = "SELECT * FROM questions";
//Get result
$results = $mysqli->query($query);
$total = $results->num_rows;
/*
* Get correct option
*/
$query = 'SELECT * FROM options WHERE WHERE question_no = $number AND is_correct = 1';
// Get result
$result = $mysqli->query($query);
// Get row
$row = $result->mysqli_fetch_assoc(); // ****Changed Line****
//Set correct choice
$correct_choice = $row['id'];
//Compare
if ($correct_choice == $selected_choice) {
//Answer is correct
$_SESSION['score']++;