Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/289.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php MySQLi面向对象重定向取决于用户角色_Php_Mysql_Oop_Authentication_Mysqli - Fatal编程技术网

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。”;
}
}