I am using Active Record on CodeIgniter. I am confused on which approach I should take. Currently, our login system let\'s the user to use username/email for the login along
@RidIculous is right. This is a correct way to do it:
$user = $this->db->escape($user);
$this->db->select('id,level,email,username');
$this->db->where("(email = $user OR username = $user)");
$this->db->where('password', $pass);
$query = $this->db->get('users');
Or a format I prefer (PHP 5+)
$user = $this->db->escape($user);
$query = $this->db
->select('id,level,email,username')
->where("(email = $user OR username = $user)")
->where('password', $pass)
->get('users');
The issue is probably that you need to add brackets when mixing AND’s and OR’s in a WHERE clause. Try this:
$this->db->select('id,level,email,username');
$this->db->where("(email = '$user' OR username = '$user')
AND password = '$pass'");
$query = $this->db->get('users');
$conditions = '(`username`="'.$username.'" OR `email`="'.$email.' OR `mobile`="'.$mobile.'"') AND `password`="'.$password.'"';
$query = $this->db->get_where('table_name', $conditions);
$result = $query->result();