循环是正确的,但不能给出正确的编号.什么';这些代码错了


Looping is right but does not give right numbering. What's wrong with these codes?

我想在状态栏中显示考试问题编号,所以我这样做,

for($i=0; $i<count($_POST['question']); $i++){
    $user=addslashes($_POST['user'][$i]);
    $question=addslashes($_POST['question'][$i]);
    $optA=addslashes($_POST['optA'][$i]);
    $optB=addslashes($_POST['optB'][$i]);
    $optC=addslashes($_POST['optC'][$i]);
    $optD=addslashes($_POST['optD'][$i]);
    $correct=addslashes($_POST['correct'][$i]);
    $qtype=addslashes($_POST['qtype'][$i]);
    $category=addslashes($_POST['category'][$i]);
    $numbering=$i;
    if($correct!=NULL){
    $insert="insert into tbl_randomq(username, question, optA, optB, optC, optD, correct, qtype, category, numbering) values('$user','$question','$optA','$optB','$optC','$optD','$correct', '$qtype', '$category', $numbering);";
    $insertrs=mysqli_query($con,$insert);
}
    }

有了这些,$编号的预期结果将是,1,2,3,4,5,6,7,8,9…依此类推,但结果集看起来像1,2,3,4,4,5,8,9,10…

为什么它6和7没有出现??:(它破坏了系统。请帮忙。我错过了一些参数吗?

为什么它6和7没有出现?

因为CCD_ 1正在返回CCD_。这意味着$_POST['correct'][$i]要么未被设置,要么正在被类型化为等于null的值。您需要检查提交的帖子数据,以验证6和7的数据是否正确提交。

关于类型铸造/杂耍:

$a = null;
echo $a == null; // true
echo $a === null; // true

$a = 0;
echo $a == null; // true
echo $a === null; // false
$a = '';
echo $a == null; // true
echo $a === null; // false

查看此页面了解有关PHP类型如何转换的更多信息。