我无法使用php在我的测验系统上查看我的正确分数

时间:2017-01-09 01:08:47

标签: php mysqli

大家好我需要一些帮助我是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.

0 个答案:

没有答案