PHP!未设置时,isset返回true
首先,我的代码:PHP!未设置时,isset返回true,php,Php,首先,我的代码: $stmt = $pdo->prepare("SELECT id FROM users WHERE username = :user_email OR email = :user_email"); $user_email = $_POST["usernameemail"]; $stm
$stmt = $pdo->prepare("SELECT id FROM users WHERE
username = :user_email OR
email = :user_email");
$user_email = $_POST["usernameemail"];
$stmt->execute(array(
'user_email'=>$user_email
));
$account_exist = $stmt->fetch();
if(!isset($account_exist)) {
$account_exist_error = '<p style="color:#F00;">Username or Email not found</p>';
}
这两个选项都没有返回任何内容,而且其他相关问题对我没有帮助,$account_exist=''在我的代码中设置得更早通常,empty($var_name)
会更可靠,对于任何null
、空白或未定义的内容都会返回true。这甚至包括空数组
但是,在本例中,您将返回一个DB对象。对于,它总是返回true,对于,它总是返回false。因此,您需要使用DB对象API。在这种情况下,您应该使用。通常,empty($var\u name)
会更可靠,对于任何null
、空白或未定义的内容,都会返回true。这甚至包括空数组
但是,在本例中,您将返回一个DB对象。对于,它总是返回true,对于,它总是返回false。因此,您需要使用DB对象API。在这种情况下,您应该使用。试试
if ($account_exist == null)
试一试
你可以用
if(!$account_exist)
而不是
if(!isset($account_exist))
因为,它的返回值是
TRUE Success. Data has been fetched
FALSE Error occurred
NULL No more rows/data exists or data truncation occurred
在这种情况下,false
和null
都是假值,可与一起使用代码>操作员。如果你使用
f(!isset($account_exist))
然后,总是设置它,因为$account\u exist
包含一个值。您可以使用
if(!$account_exist)
而不是
if(!isset($account_exist))
因为,它的返回值是
TRUE Success. Data has been fetched
FALSE Error occurred
NULL No more rows/data exists or data truncation occurred
在这种情况下,false
和null
都是假值,可与一起使用代码>操作员。如果你使用
f(!isset($account_exist))
然后,总是设置它,因为$account\u exist
包含一个值。处理数组时是否应该使用empty()empty()认为是的内容的完整列表。。。空的。例如,oolean FALSE、整数0、空字符串(“”)、NULL和不带项的数组都是空的。我修改了答案以更好地解释在处理数组时我应该使用empty()empty()认为是的内容的完整列表。。。空的。例如,oolean FALSE、整数0、空字符串(“”)、NULL和无项数组都是空的。我修改了答案以更好地解释问题的标题描述了正常行为。此外,$stmt->fetch()
确实返回了一些东西…@卑鄙的投票者
,请给出拒绝投票的原因,或者您不知道为什么拒绝投票。问题的标题描述了正常的行为。此外,$stmt->fetch()
确实会返回一些信息…@skilly down voter
,请给出否决投票的原因,或者您不知道为什么否决投票。skilly down voter,给出否决投票的原因,或者您不知道为什么否决投票?skilly down voter,给出否决投票的原因,或者您不知道否决投票的原因?