PHP空检查总是返回负数

PHP空检查总是返回负数,php,html,Php,Html,你好,Stackoverflow, 我再次来到这里,这次是关于我创建的一个PHP函数。我试图让用户设置pin,但表单总是返回“字段为空”错误。真奇怪。一切正常,即使是其他错误检查,但空值只返回负数 这是我的PHP if(isset($_POST['pin-submit'])){ // Filter the Old PIN and IMPLODE it. $pinold_1 = htmlentities($_POST['pinold-1']); $pinold_2 =

你好,Stackoverflow,

我再次来到这里,这次是关于我创建的一个PHP函数。我试图让用户设置pin,但表单总是返回“字段为空”错误。真奇怪。一切正常,即使是其他错误检查,但空值只返回负数

这是我的PHP

if(isset($_POST['pin-submit'])){

    // Filter the Old PIN and IMPLODE it.

    $pinold_1 = htmlentities($_POST['pinold-1']);
    $pinold_2 = htmlentities($_POST['pinold-2']);
    $pinold_3 = htmlentities($_POST['pinold-3']);
    $pinold_4 = htmlentities($_POST['pinold-4']);

    $array_old = array($pinold_1, $pinold_2, $pinold_3, $pinold_4);
    $oldpin = implode("|", $array_old);

    // Filter the New PIN and IMPLODE it.

    $pinnew_1 = htmlentities($_POST['pinnew-1']);
    $pinnew_2 = htmlentities($_POST['pinnew-2']);
    $pinnew_3 = htmlentities($_POST['pinnew-3']);
    $pinnew_4 = htmlentities($_POST['pinnew-4']);

    $array_new = array($pinnew_1, $pinnew_2, $pinnew_3, $pinnew_4);
    $newpin = implode("|", $array_new);

    // Filter the New Repeated PIN and IMPLODE it

    $pinnewrep_1 = htmlentities($_POST['pinnewrep-1']);
    $pinnewrep_2 = htmlentities($_POST['pinnewrep-2']);
    $pinnewrep_3 = htmlentities($_POST['pinnewrep-3']);
    $pinnewrep_4 = htmlentities($_POST['pinnewrep-4']);

    $array_newrep = array($pinnewrep_1, $pinnewrep_2, $pinnewrep_3, $pinnewrep_4);
    $newreppin = implode("|", $array_newrep);

    // Explode the User's actual PIN into pieces.

    $array_actual = explode("|", $user['slp']);

    $pinactual_1 = $array_actual[0];
    $pinactual_2 = $array_actual[1];
    $pinactual_3 = $array_actual[2];
    $pinactual_4 = $array_actual[3];

    // Check if Actual PIN is the Actual PIN.

    if($user['slp'] !== $oldpin){

    echo "<div class='alert alert-dismissible alert-danger'>";  
    echo "<strong>Hey {username}!</strong> Je actuele PIN klopt niet.  Probeer het eventjes opnieuw.";
    echo "</div>";

    // Check if the New PIN is the Same as the Repeated New PIN.

    }else if($newpin !== $newreppin){

    echo "<div class='alert alert-dismissible alert-danger'>";  
    echo "<strong>Hey {username}!</strong> Je Nieuwe PIN komt niet overeen met de Herhaling van je nieuwe PIN.";

    echo "</div>";

    // Check if all Fields are filled in.

    }else if (empty($pinold_1) || empty($pinold_2) || empty($pinold_3) || empty($pinold_4) ||
    empty($pinnewrep_1) || empty($pinnewrep_2) || empty($pinnewrep_3) || empty($pinnewrep_4) ||
    empty($pinnew_1) || empty($pinnew_2) || empty($pinnew_3) || empty($pinnew_4)){

    echo "<div class='alert alert-dismissible alert-danger'>";  
    echo "<strong>Hey {username}!</strong> Je moet elk veld ingevuld hebben. Geen enkele mag leeg zijn!";
    echo "</div>";

    // Else Save the new PIN and show a Success message.

    }else{

    echo "<div class='alert alert-dismissible alert-success'>"; 
    echo "<strong>Hey {username}!</strong> Je PIN is gewijzigd. Je kan hem direct gebruiken.";
    echo "</div>";  

    }
}
if(isset($\u POST['pin-submit'])){
//过滤旧引脚并使其内爆。
$pinold_1=htmlentities($_POST['pinold-1']);
$pinold_2=htmlentities($_POST['pinold-2']);
$pinold_3=htmlentities($_POST['pinold-3']);
$pinold_4=htmlentities($_POST['pinold-4']);
$array_old=array($pinold_1、$pinold_2、$pinold_3、$pinold_4);
$oldpin=内爆(“|”,$array_old);
//过滤新引脚并使其内爆。
$pinnew_1=htmlentities($_POST['pinnew-1']);
$pinnew_2=htmlentities($_POST['pinnew-2']);
$pinnew_3=htmlentities($_POST['pinnew-3']);
$pinnew_4=htmlentities($_POST['pinnew-4']);
$array_new=array($pinnew_1、$pinnew_2、$pinnew_3、$pinnew_4);
$newpin=内爆(“|”,$array_new);
//过滤新的重复引脚并使其内爆
$pinnewrep_1=htmlentities($_POST['pinnewrep-1']);
$pinnewrep_2=htmlentities($_POST['pinnewrep-2']);
$pinnewrep_3=htmlentities($_POST['pinnewrep-3']);
$pinnewrep_4=htmlentities($_POST['pinnewrep-4']);
$array_newrep=array($pinnewrep_1、$pinnewrep_2、$pinnewrep_3、$pinnewrep_4);
$newreppin=内爆(“|”,$array_newrep);
//将用户的实际PIN分解为碎片。
$array_actual=explode(“|”),$user['slp'];
$pinactual_1=$array_actual[0];
$pinactual_2=$array_actual[1];
$pinactual_3=$array_actual[2];
$pinactual_4=$array_actual[3];
//检查实际引脚是否为实际引脚。
如果($user['slp']!==$oldpin){
回声“;
echo“嘿{username}!我的行为是错误的。可能是错误的。”;
回声“;
//检查新销是否与重复的新销相同。
}else if($newpin!==$newreppin){
回声“;
echo“嘿{username}!Je Nieuwe PIN komt niet overeen遇到了de Herhaling van Je Nieuwe PIN。”;
回声“;
//检查是否已填写所有字段。
}else if(empty($pinold_1)| empty($pinold_2)| empty($pinold_3)| empty($pinold_4)||
空($pinnewrep_1)|空($pinnewrep_2)|空($pinnewrep_3)|空($pinnewrep_4)||
空($pinnew_1)|空($pinnew_2)|空($pinnew_3)|空($pinnew_4)){
回声“;
echo“嘿{username}!我是一只麋鹿,它的名字叫ingevuld hebben.Geen enkele mag leeg zijn!”;
回声“;
//否则保存新PIN并显示成功消息。
}否则{
回声“;
echo“嘿{username}!我的PIN是gewijzigd。我可以直接使用gebruiken。”;
回声“;
}
}
这是我的HTML(包括表单)


我的第二层脚已经穿好了。我们的行动已经开始了,我们的行动已经结束。
阿克图埃勒针
Je第二层PIN die Jenu gebruiktbij Je Magie账户。
纽维针
我是格温斯特宾。他比别人更聪明。
赫哈尔尼乌宾
赫哈勒·杰·纽韦·格文斯特·宾。这是一个很好的例子。

奥普斯兰
提前感谢,,
如果var存在且具有非空、非零值,则Pascal将返回FALSE。否则返回TRUE


注意非零部分。如果用户在其pin中使用了“0”,这也不会通过检查

0
被PHP函数视为
空的。您可以创建自己的函数,允许将
0
视为已填充,但:

function real_empty($var) { 
    if($var == '0' || !empty($var)) { 
        return false; 
    } else {
        return true; 
    }
}
然后在代码中使用
real\u empty
代替
empty


演示:

所以其中一个变量必须为空。所有这些变量都包含什么?此外,还要仔细检查手册中被视为“空”的内容<代码>以下内容被认为是空的:空字符串、0作为整数、字符串或浮点、NULL、FALSE、空数组、声明的变量,但没有值
您好,我确实回显了所有变量。没有一个是空的。它们都呼应一个数字。每个变量都应该包含1个数字,这是正确的。@chris85这是可能的。它们也可以是
0
。PHP
是否为空()
。对,那算是空的吗?是否也有允许
0
的替代方法?是否有任何示例可以同时检查这两种方法?这里有一个链接,其中包含有关
isset empty is_null
的信息,我已经使用了很多次:
function real_empty($var) { 
    if($var == '0' || !empty($var)) { 
        return false; 
    } else {
        return true; 
    }
}