大家好我需要一些帮助我是PHP的新手,我在使用这段代码时遇到了麻烦。它没有计算出正确的答案。请帮我。这是我的代码
<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.'';
}
?>
始终显示您的分数为0.