I can't view my correct score on my quiz system using php

Hi guys I need some help I am newbie in PHP and I am having a trouble with this code. It does not compute the correct answer. Please help me. here is my code

<form action="" method="post">
<?php
$f = $dbcon->query("SELECT * FROM fill_blank WHERE quiz_id = '25'") or   die(mysqli_error()); 
while($question = $f->fetch_assoc()):
?>
<div>
   <p><?php echo $question['question_title']; ?></p>
<input type="text" name="answers[<?php echo $question['question_id'] ?>]" id="">
</div>
<?php
endwhile; ?>
<br>
<input type="submit" value="Submit">
</form>

<?php if( isset( $_POST['answers'] ) ) { $answers = $_POST['answers']; $score = 0; foreach( $answers as $key => $answer ) { // check user answer compared to correct answer using key if( $answer == $question[$key]['question_answer'] ) { $score = $score + 1; } } echo 'Your score is '.$score.''; } ?>
It always display Your score is 0.

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories