0

好吧,我的登录代码有些问题。所有工作都很好,但是当我尝试从我的第二个用户那里获取该行时,它会向我显示第一个用户的行(我的意思是有关用户名、密码、电子邮件的信息,...)。

public function login($username, $password){
    global $pdo;

    $query = $pdo->prepare("SELECT * FROM users WHERE username = ? AND password = ?");
    $query->bindValue(1, $username);
    $query->bindValue(2, $password);

    $query->execute();

    $result = $query->rowCount();

    if($result === 1){
    return true;

    } else {
    return false;
     }     
  }

我不能使用 mysql_result,但是我怎么能得到它呢?

 function user_id_from_username($username){
  return mysql_result(mysql_query("SELECT user_id FROM users WHERE username = $username"), 0, 'user_id');   
}

function login($username, $password){
  $user_id = user_id_from_username($username);

  return (mysql_result(mysql_query("SELECT COUNT(user_id) FROM users WHERE username = $username AND password = $password "),0) == 1)? $user_id : false;
}

对不起我的英语^^

4

1 回答 1

0
public function login($username, $password){
    global $pdo;

    $query = $pdo->prepare("SELECT id FROM users WHERE username = ? AND password = ?");
    $query->execute(array($username, $password));
    return $query->fetchColumn();
}
于 2013-02-24T16:11:32.050 回答