我通过下面的视频教程制作了login.php文件,我正在努力制作,以便页面显示存在,而不是空白页面。我知道这个用户的存在是因为我在phpMyAdmin上用我的名字创建了这个用户。
她的代码是
<?php
include 'core/init.php';
if (user_exists('Denis') === true) {
echo 'exists';
}
die();
if(empty($_POST) === false) {
$username = $_POST['username'];
$password = $_POST['password'];
if (empty($username) === true || empty($password) === true) {
$errors[] = 'You need to enter a username and password';
} else if (user_exists($username) === false) {
$errors[] = 'We can't find that username. Have you registered?';
}
}
?>
Init.php
<?php
session_start();
error_reporting(0);
require 'database/connect.php';
require 'functions/general.php';
require 'functions/users.php';
$errors = array();
?>
您正在调用第7行的die()
函数
该函数终止正在运行的脚本
很明显,user_exists('Denis')
返回false,因为它正在通过echo 'exists';
行并调用die()
。
根据返回布尔值的方式,您可能会尝试两个"=="符号,而不是三个。它可能无法键入强制转换。
您可以尝试:
if (user_exists('Denis')) {
echo 'exists';
}
只要user_exists('Denis')
的计算结果为true(即不为空或0),您将"存在"并得到响应。
如果这不起作用,试着弄清楚user_exists()
得到错误值的原因。检查用户是否存在的逻辑可能有问题。