0

我正在尝试将 $_SESSION 设置为 mysql 查询中的“id”。我怎么做?

public function Login($email, $pass){
        if(!empty($email) && !empty($pass)){
            $st = $this->db->prepare("select email, pass, id from login where email=? and pass=?");
            $st->bindParam(1, $email);
            $st->bindParam(2, $pass);
            $st->execute();

            if ($st->rowCount() == 1){
                //login correctly
                $_SESSIONS['user_id'] = XXX;
                header('Location: main.php');
            } else{

            echo "Wrong password";
            }
        } else {
            echo "Please enter username and password";
        }
    }
4

1 回答 1

1

这是我的答案:

public function Login($email, $pass){       
    if(!empty($email) && !empty($pass)){
        $st = $this->db->prepare("select email, pass from login where email=? and pass=?");
        $st->bindParam(1, $email);
        $st->bindParam(2, $pass);
        $st->execute();

        if ($st->rowCount() == 1){
            //login correctly
            $_SESSIONS['user_id'] = $st->fetchALL(); 
            header('Location: main.php');
        } else{
            echo "Wrong password";
        }
    } else {
        echo "Please enter username and password";
    }
}
于 2012-06-25T19:13:14.450 回答