I'm new to Codeigniter and I'm trying to build a login form by following some tutorials. However, when I try to submit the login form in order to validate the credentials that have been inputted by calling the validate_login function in the login controller , I get the "Object not Found" Error. Every time I click my submit button, my URL redirects to "http://localhost/pgevCI/login/validate_login", but it still gets the Object not Found error.
Controller: login.php
<?php
class Login extends CI_Controller {
function index()
{
$data['main_content'] = 'view_login';
$this->load->view('includes/login_template', $data);
}
function validate_login()
{
$this->load->model('model_accounts');
$valid = $this->model_accounts->validate();
if($valid)
{
$data = array(
'userid' => $this->input->post('userid'),
'is_logged_in' => true
);
$this->session->set_userdata($data);
redirect('site/admin');
}
else
{
$this->index();
}
}
}
View form: view_login.php
<form action="<?php echo base_url(); ?>login/validate_login" method="POST">
<div class="row">
<div class="col-lg-6">
<div class="form-group">
<input type="text" name="userid" class="form-control" id="user-name" aria-label="..." placeholder="Enter your username">
</div><!-- /input-group -->
</div><!-- /.col-lg-6 -->
<div class="col-lg-6">
<div class="form-group">
<input type="password" name="password" class="form-control" id="user-password" aria-label="..." placeholder="Enter your password">
</div><!-- /input-group -->
</div><!-- /.col-lg-6 -->
</div><!-- /.row -->
</br>
</br>
<!-- Standard button -->
<div class="action-buttons text-center">
<button type="submit" class="btn btn-custom">Sign In</button>
<button type="button" class="btn btn-custom">Forgot your password?</button>
</div>
</form>
Model: model_accounts.php
class Model_accounts extends CI_Model {
function validate()
{
$this->db->where('userid', $this->input->post('userid'));
$this->db->where('password', md5($this->input->post('password')));
$query = $this->db->get('users');
if($query->num_rows == 1)
{
return true;
}
}
}
Base URL & Index File :
$config['base_url'] = 'http://localhost/pgevCI/';
$config['index_page'] = 'index.php';
Any help would really be appreciated! :)