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 6032757
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T05:22:52+00:00 2026-05-23T05:22:52+00:00

I am following this tutorial series to learn to make a login script. Ive

  • 0

I am following this tutorial series to learn to make a login script.
Ive done the entire tutorial, but I Keep getting thrown this error.

I am using CodeIgniter Framework 2.02

This is the error I am getting:

A Database Error Occurred
Error Number: 1054
Unknown column 'anil' in 'where clause'
SELECT user_id FROM users WHERE username = anil AND password = password
Filename: D:\xampp\htdocs\c_login\system\database\DB_driver.php
Line Number: 330<

Here is the function in my model doing the SQL:

function check_login($username, $password)
  {
    $sha1_password = sha1($password);

    // The Guy uses ' ? ' in the video for the below statement and it works
    // I tried replacing ? with $username & $password, but it didnt work..
    // When I use the ?, I think it does query the DB, but I get the error
    // Incorrect Username or Password, Even though it is correct.
    // I only have 1 record on my DB, db = c_login, table=users
    // Fields are user_id   username    password    email   name

    $query_str = "SELECT user_id FROM users WHERE username = ? AND password = ?";
    $result = $this->db->query($query_str, $username, $sha1_password);

    if($result->num_rows() == 1)
    {
        return $result->row[0]->user_id;
    }
    else
    {
        return false; 

    }
}

Also, if needed, here is my login function in my controller..

    public function login()
    {
        $this->form_validation->set_rules('username', 'Username', 'required|trim|max_length[50]|xss_clean');
        $this->form_validation->set_rules('password', 'Password', 'required|trim|max_length[50]|xss_clean');

        // If form_validation has NOT been run, load the view login form
        if($this->form_validation->run() == FALSE)            
        {
            $this->load->view('view_login');
        }
        else // Else process login
        {
            // Process input and login
            $username = $this->input->post('username');
            $password = $this->input->post('password');

            $user_id = $this->User_model->check_login($username, $password);

            if( ! $user_id)
            {
                // Login Failed Error
                $this->session->set_flashdata('login_error', TRUE);
                redirect('user/login');
            }
            else
            {
                // Log them in

                $this->session->set_userdata(array(
                                'logged_in' => TRUE, 
                                'user_id' => $user_id
                                                    ));

                redirect('user/main_page');
            }

        }

    }

So basically, It keeps saying Incorrect Username or Password if I use the Question marks in the SQL query, but if I replace them with the variables $username & $password, I get the error in the first block of code. Error Number: 1054,
What am I doing wrong? I could swear its something so simple…

  • 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-05-23T05:22:53+00:00Added an answer on May 23, 2026 at 5:22 am

    Try taking advantage of the Active Record and do the following (verbose version for clarity):

      function check_login($username, $password)
      {
        $sha1_password = sha1($password);
    
        $this->db->select('user_id');
        $this->db->where('username', $username);
        $this->db->where('password', $sha1_password);
        $result = $this->db->get('users');
    
        if($result->num_rows() == 1)
        {
            $row = $result->row();
            return $row->user_id;
        }
        else
        {
            return false; 
        }
    }
    

    Data is automatically escaped so you don’t need to worry about that. In controller, rewrite this part to:

      if($user_id == FALSE)
      {
         $this->session->set_flashdata('login_error', TRUE);
         redirect('user/login', 'refresh');
      }
      else
      {
          $this->session->set_userdata(array(
                                           'logged_in' => TRUE, 
                                           'user_id' => $user_id
                                        ));
    
          redirect('user/main_page', 'refresh');
      }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I was following this tutorial and I keep getting an error. Here is the
I'm following this tutorial attempting to learn XNA, but I'm having issues making my
I am following this tutorial http://wicket.wordpress.com/2010/01/08/template-for-building-authenticated-webapplication/ in order to learn how to make login
I am following this tutorial, trying to learn to make Magento extensions, however, in
I'm following this tutorial (seems good) for Rails. After I run ruby script/generate scaffold
I am following this tutorial and I've run the command ruby script\server and successfully
I am following this tutorial: http://docs.djangoproject.com/en/dev/ref/contrib/messages/ but I get this error: Error: No module
I am following this tutorial http://static.springsource.org/docs/Spring-MVC-step-by-step/part4.html to try and learn Spring. Everything worked fine
I am following this tutorial :- http://blogs.oracle.com/enterprisetechtips/entry/true_abstraction_composite_ui_components But it's not working for me. This
I have been following this tutorial series for OpenGL : GLUT : http://www.lighthouse3d.com/opengl/glut/ I

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.