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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T01:34:22+00:00 2026-06-15T01:34:22+00:00

still very new to CodeIgniter and trying to do the following. I may be

  • 0

still very new to CodeIgniter and trying to do the following. I may be doing this wrong, and any direction, greatly appreciated.

I have a function that is called on submit of login form, validate_creds. If successful the form logs in, if not successful I want to set an $error_msg and reload the form. The validate_creds() appears to validate correctly but as you can see on the else statement I want to reload the index() passing the $error_msg displaying the message at the top of the form.

public function index($error_msg = '')
        {
            //data
            $data['login'] = "Logged In";

            if($error_msg !== '') {
                $data['error_msg'] = $error_msg;
            }

            //view
            $this->load->view('templates/login/login_header',$data);
            $this->load->view('login/login_form', $data);
            $this->load->view('templates/login/login_footer',$data);
        }


         public function validate_creds()
                    {
                        $this->load->model('user_model');
                        $query = $this->user_model->validate();
                        if($query)//if the users creds have been validated...
                        {
                        $data = array(
                            'username' => $this->input->post('username'),
                            'is_logged_in' => true
                        );

                        $this->session->set_userdata($data);
                        redirect('gallery');
                    }

                    else
                    {
                        $error_msg = "Your username or password is not correct.";
                        $this->index($error_msg);
                    }
                }

Form Message

<?php if($error_msg != ''): ?>
  <div class="alert alert-error">
    <?php echo $error_msg; ?>
  </div>
<?php endif; ?>

What currently is happening is the $error_msg is displaying all the time.

  • 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-15T01:34:23+00:00Added an answer on June 15, 2026 at 1:34 am

    I hope this is just how it came out with copy pasting because this code is hard to read. check out php codesniffer and as an industry standard, check out some documentation on zend about php code format.

    so your logic requires the error message be injected into the index function (which I’m assuming is your action but just not labeled as so), and if it’s not injected, it doesn’t declare the error message because it’s not injected.

    i would look at $this->user_model->validate(); to ensure that’s properly handling the http request (post).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am still very new and trying my first serious data binding. I have
I'm still very new to Android, but I am trying to keep up by
I'm still very new to codeigniter. The issue i'm having is that the file
I'm still very new to rails and I'm trying to figure out what exactly
I am still very new to routing with asp.net mvc, so perhaps this is
So I'm still very new to this whole objective C think and I ran
I'm still very new to cocoa touch so please excuse any terminology that I
I still very new using Subversion. Is it possible to have a working copy
Hi there i am still very new to grails and I have not been
Hi I'm still very new to SASS and no programming guru. I have ten

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.