【发布时间】:2016-10-28 08:38:37
【问题描述】:
我正在做一个测验,下面是一个 html 复选框。
<p>3. The J2EE components includes:</p>
<p><label for="JavaDevelopmentKit">
<input type="checkbox" id="JavaDevelopmentKit" name="category[]" value="JavaDevelopmentKit"/>Java Development Kit</label></p>
<p><label for="VisualStudio">
<input type="checkbox" id="VisualStudio" name="category[]" value="VisualStudio"/>Uses Visual Studio</label></p>
<p><label for="WriteOnce">
<input type="checkbox" id="WriteOnce" name="category[]" value="WriteOnce"/>Write Once Run Anywhere technology</label></p>
这是我的 php 代码
if ($q3 == ""){
$errMsg = "<p>You must answer question 3.</p>";
}
else if (isset($_POST['JavaDevelopmentKit']) && isset($_POST['WriteOnce'])
$total++;
}
我的 PHP 复选框不起作用。
就算我改成
if ($q3 == ""){
$errMsg = "<p>You must answer question 3.</p>";
}
else if (isset($_POST['JavaDevelopmentKit'])
$total++;
}
总计不增加 1。
[编辑]
我按照@mahaidery 告诉我的方式做了,我目前的 php 是
if ($q3 == ""){
$errMsg = "<p>You must answer question 3.</p>";
}
else if (isset($_POST['category'])){
$i = 0;
foreach($_POST['category'] as $k=>$v){
if (($key == "JavaDevelopmentKit") || ($key == "WriteOnce") || ($key == "Javadatabase") || ($key == "Opendatabase" ) || ($key == "Security")){
$i++;
}
}
if($i == 5){
$total++;
}
}
显示很多Notice: Undefined variable: key
【问题讨论】:
-
如果你像默认表单一样发送数据,而不是通过ajax,你需要检查
category键而不是JavaDevelopmentKit