【发布时间】:2015-05-05 12:26:31
【问题描述】:
我目前正在使用 html 和 PHP 进行测验,我想在有多个正确答案的情况下使用复选框。用户必须得到所有正确答案才能获得每题一分。我一直在看很多教程,但似乎没有什么能完全满足我的需求。任何帮助将不胜感激!
这是其中一个问题的示例,如果您能告诉我需要添加什么:
<p class="question">2. Which clubs did Arsene Wenger manage before taking the arsenal job in 1996?</p>
<ul class="answers">
<input type="checkbox" name="q2[]" id="q2a" value="q2a"><label for="q2a" class="labela">Monaco</label><br/>
<input type="checkbox" name="q2[]" id="q2b" value="q2b"><label for="q2b" class="labelb">Paris Saint-Germain</label><br/>
<input type="checkbox" name="q2[]" id="q2c" value="q2c"><label for="q2c" class="labelc">Bayern Munich</label><br/>
<input type="checkbox" name="q2[]" id="q2d" value="q2d"><label for="q2d" class="labeld">Nagoya Grampus</label><br/>
</ul>
在一个单独的答案页面上我现在拥有什么:
<?php
$q2 = $_POST['q2'];
$total = 0;
if ($q2 == "a") { $total = $total + 0.5; }
if ($q2 == "b") { $total = $total + 0; }
if ($q2 == "c") { $total = $total + 0; }
if ($q2 == "d") { $total = $total + 0.5; }
?>
【问题讨论】:
-
您的输入是数组,因此您的 PHP 需要将它们视为数组;你没有那样做。
-
对不起,我对 php 完全陌生(截至昨天),所以你能解释一下吗?谢谢你这么快回答:)