gpt4 book ai didi

PHP 脚本报告错误的凭据

转载 作者:行者123 更新时间:2023-11-29 03:30:25 27 4
gpt4 key购买 nike

好的,这是我的身份验证代码。现在,我有一张 table 和 5 个 PHP 工作脚本,除了这个。成功登录后,用户应该被重定向到他的主页,但问题是,无论登录详细信息如何,PHP 都会回显“无法登录”错误消息。这是脚本:

session_start();
include_once'dbconnect.php';
if (isset($_SESSION['user']) != "") {
header ("Location: home.php");
}

if (isset($_POST['login'])) {
$email = mysql_real_escape_string($_POST['email']);
$pass = mysql_real_escape_string($_POST['pass']);
$sql = mysql_query("SELECT * FROM users WHERE email='".$email."'");
$num = mysql_fetch_assoc($sql);

if ($num['password'] == $pass)) {
$_SESSION['user'] = $num['user_id'];
header ("Location: home.php");
}
else {
echo "Cannot login";
}
}

有什么提示吗?谢谢

最佳答案

session_start();
include_once'dbconnect.php';
if (isset($_SESSION['user']) != "") {
header ("Location: home.php");
}

if (isset($_POST['login'])) {
$email = mysql_real_escape_string($_POST['email']);
$pass = mysql_real_escape_string($_POST['pass']);
$sql = mysql_query("SELECT * FROM users WHERE email='".$email."'");
$num = mysql_fetch_assoc($sql);
if(count($num)>0){
if ($num['password'] == $pass)) {
$_SESSION['user'] = $num['user_id'];
header ("Location: home.php");
}
else {
echo "Cannot login";
}
}else{
echo "Cannot login, email id not found";
}

}

确保您从数据库中获取密码。

关于PHP 脚本报告错误的凭据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31402831/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com