gpt4 book ai didi

mysql - 如何将 'id' 从 mysql 查询绑定(bind)到 $_SESSION

转载 作者:行者123 更新时间:2023-11-29 14:24:47 25 4
gpt4 key购买 nike

我正在尝试将 $_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";
}
}

最佳答案

这是我的回答:

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";
}
}

关于mysql - 如何将 'id' 从 mysql 查询绑定(bind)到 $_SESSION,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11195477/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com