Howdy, Stranger!

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


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

Patrick Tandoc SarmientoPatrick Tandoc Sarmiento Member Posts: 1

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

<?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.