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

  • Home
  • SEARCH
  • 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 8878261
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T19:40:21+00:00 2026-06-14T19:40:21+00:00

I am using codeigniter, i have written a function to check if a user

  • 0

I am using codeigniter, i have written a function to check if a user password exists which it does. This is my model

  1. The model: user

    public function get_some_password($username,$password) {

        $this->db->where('user_password', $password);
        $this->db->where('user_username',$username);
        $query=$this->db->get('some_users_table');
        if($query->num_rows()==1){
            return true;
        }else{
            return false;
        }
    
  2. the controller

    public function check_password() {
    $username=$this->uri->segment(3);
    $temp_pass= $this->input->post(‘current_password’);
    $password=md5($temp_pass);
    $this->user->get_some_password($username,$password);

    }
    
    1. The ajax on the view

    //done on page load

    var success1 = $(“.success”); //a div on the view that appears if success
    var error1 = $(“.error”); //a div on the view that appears if error
    success1.hide();
    error1.hide();

        $('#change_password').click(function() {
            var username = $('#username').val();
            dataString2 = $('#changpassword').serialize();
            $.ajax({
                type: "POST",
                url: '<?php echo base_url(); ?>controller_name/check_password/' + username,
                data: dataString2,
                success: function() {
                    $('.success').html('password successfully updated!'),
                            success1.slideDown('slow');
    
                },
                error: function() {
                    $('.error').html('Wrong current password!'),
                            error1.slideDown('slow');
                }
    
            });
    

The problem: Ajax loads the success div even when the username or password returned is false, where am i missing something

  • 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-14T19:40:22+00:00Added an answer on June 14, 2026 at 7:40 pm

    This is a correct behavior as jquery error is executed when response code is not 200:

    1) You can parse returned value in success method.

    e.g.

    success: function(data) {
        if (data == 'true') {
            // Success
        } else {
            // Error
        }
    }
    

    2) You can return error code from server 404, 500, 503 … To trigger execution of error function.

    e.g.

    header("Status: 404 Not Found");
    

    note: Header should executed before any output is done.

    Try in your controller:

    public function check_password() {
        $username=$this->uri->segment(3); 
        $temp_pass= $this->input->post('current_password'); 
        $password=md5($temp_pass); 
        if(!$this->user->get_some_password($username,$password)) {
            $this->output->set_status_header('500');
            return;
        }
        ...
    } 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this function on my controller (Im using CodeIgniter) that reads the database,
I am using codeigniter and have working query which take user 3 images. I
I'm using codeigniter I have this BuildTemplate function in my [HOME] controller that authenticates
I'm using CodeIgniter and I have a PHP MySQL Statement in a model: function
I have a CI Model set up with this function and ActiveRecord: function get_open_competitions()
I am using codeigniter, I have URL like this ( http://localhost/en/home/submit ). My App
In my LAMP application (using CodeIgniter), I have a call to $this->db->update... that generates
I have web services written using java which interacts with the android application only
I am building a multi-language site using codeigniter I have this language file $lang['prot_home_1']
I'm using CodeIgniter and I have a controller which processes uploads using AJAX. The

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.