Php MySQLi面向对象重定向取决于用户角色
无法找出错误所在,我想根据用户角色重定向到网站的不同部分Php MySQLi面向对象重定向取决于用户角色,php,mysql,oop,authentication,mysqli,Php,Mysql,Oop,Authentication,Mysqli,无法找出错误所在,我想根据用户角色重定向到网站的不同部分 if(isset($\u POST['submit'])){ $stmt=$conn->prepare('SELECT id,password FROM accounts WHERE email=?'); $stmt->bind_param('s',$_POST['email']); $stmt->execute(); $stmt->store_result(); 如果($stmt->num_rows>0){ $stmt->bind_re
if(isset($\u POST['submit'])){
$stmt=$conn->prepare('SELECT id,password FROM accounts WHERE email=?');
$stmt->bind_param('s',$_POST['email']);
$stmt->execute();
$stmt->store_result();
如果($stmt->num_rows>0){
$stmt->bind_result($id,$password);
$stmt->fetch();
if(password_verify($_POST['password'],$password)){
会话_重新生成_id();
$\u会话['loggedin']=TRUE;
$row=$result->fetch_assoc();
if($row['role']=='admin'){
标题('Location:admin.php');
}else if($row['role']=='user'){
标题('Location:profile.php');
}
}否则{
$password_incorrecta=““Contraseña incorrecta!我有olvidado tu Contraseña puedes。”;
}
}
您没有在查询中选择角色
列,因此您永远无法对照该值进行检查。您也在使用存储结果()
,但保留一些语句方法。建议您选择其中一种(此代码删除存储结果()
,只使用简单准备的语句)
if(isset($\u POST['submit'])){
$stmt=$conn->prepare('SELECT id,password,role FROM accounts WHERE email=?');
$stmt->bind_param('s',$_POST['email']);
$stmt->execute();
$stmt->bind_result($id、$password、$role);
如果($stmt->fetch()&&password\u验证($\u POST['password'],$password)){
会话_重新生成_id();
$\u会话['loggedin']=true;
如果($role=='admin'){
标题('Location:admin.php');
出口
}elseif($role=='user'){
标题('Location:profile.php');
出口
}
}否则{
$password_incorrecta=““Contraseña incorrecta!我有olvidado tu Contraseña puedes。”;
}
}