繁体   English   中英

SQL不返回数据库结果

[英]SQL not return database result

我有一个带有“用户”表的数据库。 在用户表中,我有以下列:“ 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();

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM