PHP Wampserver

Report
Question

Please briefly explain why you feel this question should be reported .

Report
Cancel

How do i fix this error to create my process page to move to the next question on my database:
Fatal error: Call to a member function fetch_assoc() on a non-object in C:\wamp\www\quiz\process.php on line 32

<?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
in progress 0
PHP 2 weeks 1 Answer 44 views 0

About ahmad

Answer ( 1 )

  1. ritwik

    Please briefly explain why you feel this answer should be reported .

    Report
    Cancel

    Your SQL query is failing and that is why you are receiving that error. May be it’s because you have used WHERE clause twice. Check you SQL statement.

Leave an answer

Browse

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>