带有2个正确答案的PHP复选框
我正在做一个测验,下面是一个html复选框带有2个正确答案的PHP复选框,php,checkbox,Php,Checkbox,我正在做一个测验,下面是一个html复选框 <p>3. The J2EE components includes:</p> <p><label for="JavaDevelopmentKit"> <input type="checkbox" id="JavaDevelopmentKit" name="category[]" value="JavaDevelopmentKit"/>Ja
<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>
3。J2EE组件包括:
Java开发工具包
使用VisualStudio
写一次,随时随地运行技术
这是我的php代码
if ($q3 == ""){
$errMsg = "<p>You must answer question 3.</p>";
}
else if (isset($_POST['JavaDevelopmentKit']) && isset($_POST['WriteOnce'])
$total++;
}
if($q3==“”){
$errMsg=“您必须回答问题3.”;
}
else if(isset($_POST['JavaDevelopmentKit'])和&isset($_POST['WriteOnce']))
$total++;
}
我的PHP for复选框不起作用
即使我把它改成
if ($q3 == ""){
$errMsg = "<p>You must answer question 3.</p>";
}
else if (isset($_POST['JavaDevelopmentKit'])
$total++;
}
if($q3==“”){
$errMsg=“您必须回答问题3.”;
}
else if(isset($\u 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++;
}
}
if($q3==“”){
$errMsg=“您必须回答问题3.”;
}
else if(isset($_POST['category'])){
$i=0;
foreach($_POST['category']为$k=>$v){
如果($key==“JavaDevelopmentKit”)| |($key==“WriteOnce”)| |($key==“Javadatabase”)| |($key==“Opendatabase”)| |($key==“安全性”)){
$i++;
}
}
如果($i==5){
$total++;
}
}
它显示了大量的
注意:未定义变量:key
您在PHP中做错了。
这就是你能做到的
<?php
if(isset($_POST['category'])){
//You can also count the total checked by the following line of code
//$count = count($_POST['category']);
//or
//You can loop thru
$i=0;
foreach($_POST['category'] as $k=>$v){
//$k is the number $v hold the value..
//you can add the counter here like
$i++;
}
if($i <= 2){
//do your stuff here
}
}
?>
您在PHP中做错了。 这就是你能做到的
<?php
if(isset($_POST['category'])){
//You can also count the total checked by the following line of code
//$count = count($_POST['category']);
//or
//You can loop thru
$i=0;
foreach($_POST['category'] as $k=>$v){
//$k is the number $v hold the value..
//you can add the counter here like
$i++;
}
if($i <= 2){
//do your stuff here
}
}
?>
如果您发送默认表单之类的数据,而不是通过ajax,则需要检查category
key而不是JavaDevelopmentKit
如果您发送默认表单之类的数据,而不是通过ajax,则需要检查category
key而不是JavaDevelopmentKit
嘿,您能帮我吗?我按照您所说的那样编辑了我的php代码,但是没有有错误。谢谢,你能帮我吗?我按照你说的编辑了我的php代码,但是有错误。谢谢