为什么我的IF声明不能显示我想要的结果?

nod*_*ect -4 php

我的customer_profile表中有两列,"birthdate"和"gender".我想要检测用户是否已完成他们的个人资料.但是,通过使用以下条件,我无法检查客户是否已完成其个人资料.它只返回"配置文件完成".

我试过改变条件"&& to ||" 并且"|| to &&"和all to"&&"但它会返回意外的结果.

有这么多条件的原因是因为有时客户没有填写数据或将其留空或在性别字段或生日字段中键入"0".如果只有两个条件,我就不必面对这个问题了.

下面是我比较这两列的代码.我要检查的是客户数据是否为空; 这两列上为NULL或0.

$sql_stmt = "SELECT customer_id, first_name, email, phone, birthdate, gender FROM customers
                        WHERE customer_id = 1 LIMIT 1";
$sql = mysqli_query($conn, $sql_stmt) or die(mysqli_error($conn));
$row = mysqli_fetch_array( $sql );
extract($row);

if(($birthdate == '' && $birthdate == NULL && $birthdate == '0000-00-00') || ($gender == '' && $gender == 0 && $gender == NULL)){
     echo "Profile Not Complete";
} else { 
     echo "Profile Complete"; 
}
Run Code Online (Sandbox Code Playgroud)

Mar*_*ude 7

这应该是这样的:

if(($birthdate == '' || $birthdate == NULL || $birthdate == '0000-00-00') || ($gender == '' || $gender == 0 || $gender == NULL)){
     echo "Profile Not Complete";
} else { 
     echo "Profile Complete"; 
}
Run Code Online (Sandbox Code Playgroud)

这意味着:

如果组$ birthdate为空或null或0000000,或者性别为空或零或空...

编辑

我建议使用这种条件方式:

if(empty($birthdate) || empty($gender)){
     echo "Profile Not Complete";
} else { 
     echo "Profile Complete"; 
}
Run Code Online (Sandbox Code Playgroud)

了解更多empty():

http://php.net/manual/en/function.empty.php