不确定我在这里做错了什么,但是输出总是空的。只有在没有选择答案的情况下,脚本才会输出"you not select an answer“,否则会输出给定的答案:
我已经更新了前面提到的脚本,但即使给出了答案,仍然得到了空输出:/
感谢大家到目前为止的帮助,但即使是下面的代码也不起作用,如果没有答案,它现在只是输出为空,但如果你填写了它,它就会正确地回应答案。
if (empty( $a1 )) {
echo"<li>\n<h2>1. " . $q1[0] . "</h2>\n"
. "<p>You did not select an answer</p>\n"
. "</li>\n";
}
else {
echo"<li>\n<h2>1. " . $q1[0] . "</h2>\n"
. "<p><strong>" . $q1[$a1] . ":</strong></p>\n"
. "<p>" . $r1[$a1] . "</p>\n"
. "</li>\n";
}完全忘记显示这部分了!!
// get local copies of single answers
$a1 = trim(isset($_POST['a1'])?$_POST['a1']:99);
$a3 = trim(isset($_POST['a3'])?$_POST['a3']:99);
$a4 = trim(isset($_POST['a4'])?$_POST['a4']:99);
$a5 = trim(isset($_POST['a5'])?$_POST['a5']:99);发布于 2013-06-13 17:33:11
不要使用if(empty($a1))或if(isset($a1))来使用if($a1 == null)
发布于 2013-06-13 17:32:07
空字符串不是null
$a1 = '';
if ($a1 == null) // is wrong应该是
$a1 = '';
if ($a1 === '')或
if (empty($a1))发布于 2013-06-13 17:33:00
空与null try不同
if ($a === '')这也会考虑代码质量更好的类型
https://stackoverflow.com/questions/17083675
复制相似问题