我要分开用户/管理员登录名
if ($user_id)
{
//Create Session
$user_data = array(
'user_id' => $user_id->id,
'username' => $username,
'email' => $user_id->email,
'name' =>$name,
'login' => true
);
$this->session->set_userdata($user_data);
if($user_data['username'] != 'Admin');
{
$this->session->set_flashdata('user_loggedin', 'You are now logged in.');
redirect('users/dashboard');
}
if($user_data['username'] == 'Admin');
{
//Set Message
$this->session->set_flashdata('user_loggedin', 'You are now logged in.');
redirect('users/admin_dashboard');}
}
else
{
$this->session->set_flashdata('login_failed', 'Login is invalid.');
redirect('users/login');
}
}
告诉其他条件错误。请建议 解决该错误的任何其他方法。我犯了什么错误。
答案 0 :(得分:0)
请尝试此操作,您有一个额外的右括号
if ($user_id)
{
//Create Session
$user_data = array(
'user_id' => $user_id->id,
'username' => $username,
'email' => $user_id->email,
'name' =>$name,
'login' => true
);
$this->session->set_userdata($user_data);
if($user_data['username'] != 'Admin');
{
$this->session->set_flashdata('user_loggedin', 'You are now logged in.');
redirect('users/dashboard');
}
if($user_data['username'] == 'Admin');
{
//Set Message
$this->session->set_flashdata('user_loggedin', 'You are now logged in.');
redirect('users/admin_dashboard');
}
else
{
$this->session->set_flashdata('login_failed', 'Login is invalid.');
redirect('users/login');
}
}
答案 1 :(得分:0)
if($ user_data ['username'] =='Admin'); 这是错误的。 if($ user_data ['用户名'] =='管理员') 。并添加右括号
答案 2 :(得分:0)
尝试以下代码。你有错别字。
if ($user_id)
{
//Create Session
$user_data = array(
'user_id' => $user_id->id,
'username' => $username,
'email' => $user_id->email,
'name' =>$name,
'login' => true
);
$this->session->set_userdata($user_data);
if($user_data['username'] != 'Admin');
{
$this->session->set_flashdata('user_loggedin', 'You are now logged in.');
redirect('users/dashboard');
}
else if($user_data['username'] == 'Admin');
{
//Set Message
$this->session->set_flashdata('user_loggedin', 'You are now logged in.');
redirect('users/admin_dashboard');
}
else
{
$this->session->set_flashdata('login_failed', 'Login is invalid.');
redirect('users/login');
}
}