计算变量等于TRUE的实例

时间:2016-02-21 23:19:39

标签: php

在测验网站上工作,当用户提交答案时fetch等于$perQuestionScore,答案正确时true,当错误时为false。我试图在其他地方找到$perQuestionScore等于为真的实例,但是它似乎没有效果。

我的代码如下所示

   <?php    

$perQuestionScore = 0;

if (isset($_POST['grader'])) {

if(isset($_POST[$chosen]))

{
        $choice= $_POST[$chosen];

    if (strpos($choice, $correctOne) !== false) {

        $perQuestionScore++;

    echo $_POST[$chosen] . "" . " is the correct answer";

} elseif (strpos($choice, $correctOne) == false) { echo $_POST[$chosen] . "" . " is the Wrong answer";

} else  {

echo "You did not choose an answer"; { 



}
}
}               
}
     }
     echo "<input id=grader' type='submit' name='grader' value='Grade Quiz'>" . "</form>";
                    echo $perQuestionScore * 10;

} 





$conn->close();
?> 

1 个答案:

答案 0 :(得分:0)

我建议将其简化为:

<?php 


$perQuestionScore = 0; //initialize var

if ($choice == $correct) {
    $perQuestionScore++; //add 1 if correct
} 


echo $perQuestionScore * 10; //i guess you want it times 10