Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7721077
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T03:49:58+00:00 2026-06-01T03:49:58+00:00

I am using Active Record on CodeIgniter. I am confused on which approach I

  • 0

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 with the password. But my current active record, seems to let the user logged in if he choose to use the email + no password.

Right now this is my query:

$this->db->select('id,level,email,username');
$this->db->where('email',$user);
$this->db->or_where('username',$user);
$this->db->where('password',$pass);
$query = $this->db->get('users');

if($query->num_rows>0)
  return TRUE;
else
  return FALSE;

Sample inputs:

  • Username: test | Password: pass | Result: Success
  • Username: test | Password: empty | Result: Failed
  • Username: test@domain.com | Password: pass | Result: Success
  • Username: test@domain.com | Password: empty | Result: Success

The fourth test input must be Failed in result, but it seems that it logs the user even if the password is empty.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T03:50:00+00:00Added an answer on June 1, 2026 at 3:50 am

    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');
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using CodeIgniter's Active Record class to query the MySQL database. I need to
I'm using Codeigniter and the Active Record class to build a simple API in
I want to implement a sql query using CodeIgniter Active Record class. The query
Using CodeIgniter's Active Record class and MySQL, I have a table of posts with
I am trying to form a query using codeigniter's active record, the search is
I'm using Codeigniter's Active Record Class. So the query looks something like this: $query
I'm using CodeIgniter's active record features but I'm not able to select the data
I'm using CodeIgniter's Active Record Classes and I'm retrieving an error using the following
I'm using CodeIgniter. Let's say I have a model for the current user and
I am using CodeIgniter Active Record Class to generat tables, my code snippet below.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.