2019-04-06 07:42
浏览 69


I made a login form, and while the registration form is fully functional, the login form doesn't seem to be working. $user and $pwd get declared, but $pwd_hashed stayes empty.

if(isset($_GET['login'])) {
   $user = $_POST['user'];
   $pwd = $_POST['pwd'];

   $stmt = $pdo->prepare("SELECT * FROM users WHERE user = :user");
   $result = $stmt->execute(array('user' => $user));
   $pwd_hash = $stmt->fetch();

   if ($pwd_hash !== false && password_verify($pwd, $pwd_hash['password'])) {
      $_SESSION['userid'] = $pwd_hash['id'];
      die('Login successful<br>');
   } else {
      $errorMessage = "Username or password doesn't match<br>";
if(isset($errorMessage)) {
   echo $errorMessage;

Should the code work like this and I just got something wrong with naming, or is there an error in the code?

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dpqmu84646 2019-04-06 10:40

    This form is included in another site, in which a database was already selected. By removing it (;dbname=test) and specifying the users data base (users.users) the issue is gone.

    打赏 评论

相关推荐 更多相似问题