duancaoqin6683 2017-11-28 05:37 采纳率: 0%
浏览 111
已采纳

SQL不返回数据库结果

I have a database with a "users" table. In users table I have following column:"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();
}

The problem is when I try to login with my uid and password which has been created in sql database, It's return : "../index.php?login_not_good".What should I do?

  • 写回答

1条回答 默认 最新

  • dormbaf90464 2017-11-28 05:45
    关注

    As variant you can use named parameters

    $sql = "SELECT * FROM users WHERE user_uid = :uid";
    $result = $conn->prepare($sql);
    $result->bindParam(':uid', $uid);
    $result->execute();
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 想问一下树莓派接上显示屏后出现如图所示画面,是什么问题导致的
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号