gpt4 book ai didi

php - SQL不返回数据库结果

转载 作者:行者123 更新时间:2023-11-29 10:30:16 24 4
gpt4 key购买 nike

我有一个带有“用户”表的数据库。在用户表中,我有以下列:“user_id”,“user_first”,“user_last”,“user_email”,“user_phone”,“user_uid”,“user_password”。

if (isset($_POST['submit'])) {
include 'dbh.inc.php';
$uid = $_POST['uid'];
$pwd = $_POST['password'];

if(empty($uid) || empty($pwd)) {
header("Location: ../index.php?login=empty");
exit();
} else {
try {
$sql = "SELECT * FROM users";
$result = $conn->prepare(
$sql . "WHERE user_uid = ?"
);
$result->bindParam( 1, $uid, PDO::PARAM_STR );
$result->execute();
} catch (Exception $e) {
echo"Bad Query";
}
$resultCheck = $result->rowCount();
if ($resultCheck < 1 ) {
header("Location: ../index.php?login_not_good");
exit();
} else {
$row = $result->fetch(PDO::FETCH_ASSOC);
if($row) {
//De-hashing the password
$hashedPwdCheck = password_verify($pwd,$row['user_password']);
if ($hashedPwdCheck == false) {
header("Location: ../index.php?login=error");
exit();
} elseif ($hashedPwdCheck == true) {
//Log in the user here
$_SESSION['u_id'] = $row['user_id'];
$_SESSION['u_first'] = $row['user_first'];
$_SESSION['u_last'] = $row['user_last'];
$_SESSION['u_email'] = $row['user_email'];
$_SESSION['u_uid'] = $row['user_uid'];
header("Location: ../index.php?login=login_success");
exit();
}
}
}
}
} else {
header("Location: ../index.php?login=error");
exit();
}

问题是当我尝试使用在sql数据库中创建的uid和密码登录时,它返回:“../index.php?login_not_good”。我该怎么办?

最佳答案

作为变体,您可以使用命名参数

$sql = "SELECT * FROM users WHERE user_uid = :uid";
$result = $conn->prepare($sql);
$result->bindParam(':uid', $uid);
$result->execute();

关于php - SQL不返回数据库结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47524667/

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