【发布时间】:2019-01-06 18:06:15
【问题描述】:
我刚刚将我的 PHP 安装版本从 5.6 升级到了 7.2。我在登录页面上使用了count() 函数,如下所示:
if (!empty($_POST['username']) && !empty($_POST['password'])):
$records = $conn->prepare('SELECT id,username,password FROM users WHERE username = :username');
$records->bindParam(':username', $_POST['username']);
$records->execute();
$results = $records->fetch(PDO::FETCH_ASSOC);
$message = '';
if (count($results) > 0 && password_verify($_POST['password'], $results['password'])) {
$_SESSION['user_id'] = $results['id'];
header("Location: /");
} else {
$message = 'Sorry, those credentials do not match';
}
endif;
经过搜索,找到了和这个类似的问题和答案,但是都和WordPress有关,找不到Pure PHP的解决方案。
【问题讨论】:
-
我猜 $results 不是一个数组?在检查其他内容之前尝试使用 bool is_array (mixed $var) 进行检查。
-
转储
$results。 -
我认为“$results”的问题。您能否更新您的问题,例如如何将数据放入 $results 变量?
-
转储
$results:var_dump($results)。由于查询可能失败,它可能会返回一个 bool (false)。
标签: php session post count php-7.2