php - 用php制作登录脚本的问题
问题描述
我需要一些有关我网站的登录脚本的帮助。我只收到“nouser”错误,但我知道我有一个帐户并且它是正确的登录名。就像它跳过了脚本的登录部分。我检查了大括号,我认为我是对的。好像从数据库中提取有问题?
任何人都可以看到任何错误或可以给我如何改进它的提示吗?
if (isset($_POST['login-submit'])) {
require "dbh.i.php";
$mailuid = $_POST['mailuid'];
$password = $_POST['pwd'];
if (empty($mailuid) && empty($password)) {
header("Location: ../index.php?error=emptyfields");
exit();
} else {
$sql = "SELECT * FROM users WHERE uidUsers=? OR emailUsers;";
$stmt = mysqli_stmt_init($connect);
if (!mysqli_stmt_prepare($stmt, $sql)) {
header("Location: ../index.php?error=sqlerror");
exit();
} else {
mysqli_stmt_bind_param($stmt, "ss", $mailuid, $mailuid);
mysqli_stmt_execute($stmt);
$result = mysqli_stmt_get_result($stmt);
if ($row = mysqli_fetch_assoc($result)) {
$pwdCheck = password_verify($password, $row['pwdUsers']);
if ($pwdCheck == false) {
header("Location: ../index.php?error=wrongpwd");
exit();
} else if ($pwdCheck == true) {
session_start();
$_SESSION[userId] = $row['idUsers'];
$_SESSION[userUid] = $row['uidUsers'];
header("Location; ../index.php?login=success");
exit();
} else {
header("Location: ../index.php?error=wrongpwd");
exit();
}
} else {
header("Location: ../index.php?error=nouser");
exit();
}
}
}
} else {
header("Location: ../index.php?signup");
exit();
}
解决方案
我认为您的这部分代码是错误的:
$sql = "SELECT * FROM users WHERE uidUsers=? OR emailUsers;";
$stmt = mysqli_stmt_init($connect);
if (!mysqli_stmt_prepare($stmt, $sql)) {
header("Location: ../index.php?error=sqlerror");
exit();
} else {
mysqli_stmt_bind_param($stmt, "ss", $mailuid, $mailuid);
您的查询中只有一个占位符要替换:SELECT * FROM users WHERE uidUsers=? OR emailUsers;
,但您将其替换了两次:
mysqli_stmt_bind_param($stmt, "ss", $mailuid, $mailuid);
尝试将您的查询更改为:
SELECT * FROM users WHERE uidUsers=? OR emailUsers=?;
推荐阅读
- java - 如果spring jpa中不存在列,如何将实体属性默认值标记为null
- python-3.x - 替换数据框中单元格内的多个值 - Python/Pandas
- python - 为什么代码在 kivy 启动器中不起作用?(我错过了什么?)
- html - 如何垂直居中大于其父对象的对象?
- javascript - 如何用 JS/jQuery 解决这个问题(活动菜单类)的想法
- c++ - 标准库 to_string(double) 在 vs2015 中给出了错误的值。有什么解决办法吗?
- monitoring - 如何使用普罗米修斯获得休息服务器的请求数?
- java - 在多个 Spring Boot API 之间共享通用代码
- java - 再说一遍:如何解决“集合映射中的重复列”?
- excel - VBA .Range Two Brackets or Parentheses