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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T06:56:30+00:00 2026-06-07T06:56:30+00:00

As I am new to code igniter and MVC, I am slowly but surely

  • 0

As I am new to code igniter and MVC, I am slowly but surely getting my login form to log a user in via data I’ve stored in the db.

I have pieced together my current version from articles and advice from forums, however I am a little confused at this point as to why it seems that data is not being stored and sent properly.

I have my login form set up to re-load the form if the password is incorrect ( eventually will add a message)

That being said, when I put in the proper login info it reloads the page. That can only tell me that I am not communicating with the db properly or not sending and or storing info with my $data variable properly.

Here is what I have code wise:

Model:

<?php

class User_model extends CI_Model {
   function __construct()
        {
            // Call the Model constructor
            parent::__construct();
        }

    function login($data = array())
    {
    // validate data
    if( !empty($data) ) return FALSE;

    // retrieve query
    $query = $this->db
            ->from('users')
            ->where($data)
            ->get();

    // Check if query row exists
    if($query->row())
    {
        // Query row exists, return query row
        return $query->row();
    }
    else
    {
        // Query row doesn't exist, return FALSE
        return FALSE;
    }
  }
}

View:

title>Login</title>

<!--MAKE SURE SIGNED OUT HEADER IS IMPLEMENTED FOR ALL SIGNED OUT PAGES INCLUDING THIS ONE-->

<div class="structure clearfix">
    <h1 class="title_header">
        Sign In
    </h1>
    <div id="signin_form">
        <?php
        echo validation_errors(); 
        echo form_open('auth/validate_credentials');
        echo "<div class='form_text_signin'>";
        echo "Email";
        echo "</div>";
        echo form_input('email');
        echo "<div class='form_text_signin'>";
        echo "Password";
        echo "</div>";
        echo form_input('password');
        echo form_submit('submit', 'Submit');
        echo form_close();
        ?>
    </div>
</div>

Controller:

<?php
class Auth extends CI_Controller {
    function __construct()
        {
            // Call the Model constructor
            parent::__construct();
        }

    // this is automatically called if no other function is called
    // it simply turns around and calls the login() function to show the login page

    public function index() {

        $this->login();
    }

    public function login() {   
    $data['main_content'] = 'auth/login';
    $this->load->view('includes/templates/main_page_template', $data);

    }

    function validate_credentials () {
        $query = $this->load->model('user_model');



        if($query)
        {
            $data = array(
                'email' => $this->input->post('email'),
                'password' => $this->input->post('password'),
                'is_logged_in' => true
            );

            $this->session->set_userdata($data);
            redirect('account/dashboard');
        }
        else
        {
            $this->index();
        }
    }
}

thanks in advance.

  • 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-07T06:56:32+00:00Added an answer on June 7, 2026 at 6:56 am

    It doesn’t look like you’re calling the login method from your user_model class at any point – you’re just instantiating the class. You should be calling the model method from your controller – I haven’t tested this code but hopefully it gets you on the right track:

        function validate_credentials () {
            $this->load->model('User_model');
            $data = array(
                'email' => $this->input->post('email'),
                'password' => $this->input->post('password')
            );
            $query = $this->User_model->login($data);
    
            if($query)
            {
                $data['is_logged_in'] = true;
                $this->session->set_userdata($data);
                redirect('account/dashboard');
            }
            else
            {
                $this->index();
            }
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm still new to code igniter and I'm having problems getting the login system
I am brand new to Code Igniter but I can't seem to find a
I'm new to code igniter but I've been watching many youtube videos and I'm
I'm new to code igniter. I'm following the form validation tutorial found at: http://www.codeignitor.com/user_guide/libraries/validation.html
I am new to code igniter, coming from a solid CakePHP background. The user
I am trying to get the new PDO driver running in Code Igniter 2.1.1
I have this function in a Code Igniter model that creates a new video.
I'm new to PHP, started with Code Igniter and MAMP. I start the server
im all new to framework. so the structure of code igniter looks like: system
I'm pretty new to code igniter. Is there best practice for serving different view

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.