我正在尝试根据我找到的教程创建一个简单的测验。http://css-tricks.com/building-a-simple-quiz/
不幸的是,这让我转动我的轮子,答案可能很简单。
我得到了这个完美的工作。我想更改功能。我希望它做其他事情,而不是计算答案。
- 我想再次显示问题。
- 此外,选择的答案和正确的答案。回应答案,而不是字母 A、B、C、D。
对我来说,进行测验并说您错过了 2 并且不显示错过了哪些问题,这似乎很愚蠢。
我宁愿避免使用数据库。它可以在屏幕上、在新屏幕上或通过电子邮件发送。没有偏好。有什么建议么?
这是来自上述网站的代码:
<form action="grade.php" method="post" id="quiz">
<li>
<h3>CSS Stands for...</h3>
<div>
<input type="radio" name="question-1-answers" id="question-1-answers-A" value="A" />
<label for="question-1-answers-A">A) Computer Styled Sections </label>
</div>
<div>
<input type="radio" name="question-1-answers" id="question-1-answers-B" value="B" />
<label for="question-1-answers-B">B) Cascading Style Sheets</label>
</div>
<div>
<input type="radio" name="question-1-answers" id="question-1-answers-C" value="C" />
<label for="question-1-answers-C">C) Crazy Solid Shapes</label>
</div>
<div>
<input type="radio" name="question-1-answers" id="question-1-answers-D" value="D" />
<label for="question-1-answers-D">D) None of the above</label>
</div>
</li>
</form>
<input type="submit" value="Submit Quiz" />
然后是 PHP 脚本:
<?php
$answer1 = $_POST['question-1-answers'];
$answer2 = $_POST['question-2-answers'];
$answer3 = $_POST['question-3-answers'];
$answer4 = $_POST['question-4-answers'];
$answer5 = $_POST['question-5-answers'];
$totalCorrect = 0;
if ($answer1 == "B") { $totalCorrect++; }
if ($answer2 == "A") { $totalCorrect++; }
if ($answer3 == "C") { $totalCorrect++; }
if ($answer4 == "D") { $totalCorrect++; }
if ($answer5) { $totalCorrect++; }
echo "<div id='results'>$totalCorrect / 5 correct</div>";
?>
任何建议或链接将不胜感激。我的谷歌技能让我失望了。我想搜索的所有内容都会带来不相关的内容。