0

我有这个 If 语句来检查用户提交的数据。首先将数据转换为一个数组,然后将其传递给该 if 语句所在的函数。

$errCount = 0;
$errMSG ='';
// Check Name
if ($submitData['FullName'] != '') {
    if (strlen ($submitData['FullName']) < 4) {
        $errCount + 1;
        $errMSG .='The Full Name was too short!';
    }
} else {
    $errCount + 1;
    $errMSG .='The Full Name Field was left blank!';
}

当它运行时,即使是空字符串,也不会触发任何错误。

我错过了什么吗?

谢谢!

4

2 回答 2

0

增加 $errCount 变量时,您没有为其赋值;

$errCount = 0;
$errMSG ='';
$submitData['FullName']='';
// Check Name
if ($submitData['FullName'] != '') {

if (strlen ($submitData['FullName']) < 4) {
    $errCount=$errCount + 1; // or u can write  $errCount++;
    $errMSG .='The Full Name was too short!';
    }
} else {

 $errCount=$errCount + 1; // or u can write  $errCount++;
$errMSG .='The Full Name Field was left blank!';
}

echo $errMSG;

echo $errCount;

这将工作......

于 2013-02-20T05:24:27.750 回答
0
$errCount = 0;
$errMSG ='';
// Check Name

if(isset($submitData['FullName']) && strlen ($submitData['FullName'])>0 && strlen ($submitData['FullName'])<4)
{
    $errCount++;
    $errMSG .='The Full Name was too short!';
}
else if($submitData['FullName'] == '')
{
    $errCount++;
    $errMSG .='The Full Name Field was left blank!';
}
else
{
    //success
}
于 2013-02-20T05:25:03.820 回答