code:
<?php
if($this->input->post('login'))
{
$username = $this->input->post('username');
$password = $this->input->post('password');
$this->db->select('firstname,password');
$this->db->from('client');
$where = "firstname='$username' and password = '$password'";
$this->db->where($where);
$query = $this->db->get();
echo $this->db->last_query();
$result = $query->result_array();
$num = $query->num_rows();
if($num >'0')
{
$this->db->select('firstname,password,client_id');
$this->db->from('client');
$where = "firstname ='$username' and password = '$password'";
$this->db->where($where);
$query = $this->db->get();
echo $this->db->last_query();
$result = $query->result_array();
$this->session->set_userdata('client_id',$result);
$Session = $this->session->set_userdata('user_type',$result);
if($session == true)
{
redirect('/admins/home');
}
else
{
redirect('/partner/home');
}
}
else
{
echo "<p style='color: red;font-weight: bold;'>Wrong username or password! </p>";
}
}
?>
<form method="post">
<input type="text" name="username" placeholder="Username"/>
<input type="password" name="password" placeholder="Password"/>
<input type="submit" name="login" id="login" value="login">
</form>
This might be duplicate question. Here, I have a table in my database having name client. In this table I m declare a column name user type. I want to login according to user type. for example if my user type is admin then only those user can login who having user type admin similarly if user type is partner then only partner can login. So, how can I do this ? please help me.
Thank You
Try this code:
if($this->input->post('login'))
{
$username = $this->input->post('username');
$password = $this->input->post('password');
$this->db->from('client');
$this->db->where('firstname',$username);
$this->db->where('password',$password);
$query = $this->db->get();
$result = $query->result_array();
if($query->num_rows() > 0)
{
$this->session->set_userdata('client_id',$result);
if($query->row('user_type') == 'admin'){
redirect('/admins/home');
}elseif ($query->row('user_type') == 'partner') {
redirect('/partner/home');
}else{
redirect('home');
}
}else{
echo "<p style='color: red;font-weight: bold;'>Wrong username or password! </p>";
}
}
NOTE: You should separate all your code Model, View and Controller
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments