我正在尝试通过填写一些测验来获得分数。但是,我正在使用 SESSIONS 并且我的分数数据不会总结。我看到一个 3 出现了,但是有 6 个问题,每个好的答案都值得 3 分。因此,如果所有答案都正确,总分应该是 18。
有人可以告诉我如何解决这个问题吗?
QUIZ.PHP
<?php
session_start();
$_SESSION["vraag1_antwoorden"] = $_POST["vraag1_antwoorden"];
$_SESSION["vraag2_antwoorden"] = $_POST["vraag2_antwoorden"];
$_SESSION["vraag3_antwoorden"] = $_POST["vraag3_antwoorden"];
$_SESSION["vraag4_antwoorden"] = $_POST["vraag4_antwoorden"];
$_SESSION["vraag5_antwoorden"] = $_POST["vraag5_antwoorden"];
$_SESSION["vraag6_antwoorden"] = $_POST["vraag6_antwoorden"];
?>
结果.PHP
<?php
session_start();
$answer1 = $_SESSION['vraag1_antwoorden'];
$answer2 = $_SESSION['vraag2_antwoorden'];
$answer3 = $_SESSION['vraag3_antwoorden'];
$answer4 = $_SESSION['vraag4_antwoorden'];
$answer5 = $_SESSION['vraag5_antwoorden'];
$answer6 = $_SESSION['vraag6_antwoorden'];
$totalCorrect = 0;
if ($answer1 == "A") { $totalCorrect += 3;}
if ($answer2 == "C") { $totalCorrect += 3;}
if ($answer3 == "C") { $totalCorrect += 3;}
if ($answer4 == "C") { $totalCorrect += 3;}
if ($answer5 == "B") { $totalCorrect += 3;}
if ($answer6 == "C") { $totalCorrect += 3;}
echo $_SESSION['totalcorrect'] = $totalCorrect;
session_destroy();
?>