I am newbie to Codeigniter and trying to build a login page from the tutorial codeigniter login. Now when I tried to login after entering my username and password, I am getting the following error.
A PHP Error was encountered
Severity: Notice
Message: Undefined property: Verifylogin::$form_validation
Filename: controllers/verifylogin.php
Line Number: 18
EDITED:
my verifylogin.php
file is
<?php
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
class Verifylogin extends CI_Controller
{
function __construct() {
parent::__construct();
}
function index()
{
$this->load->helper(array('form', 'url'));
$this->load->model('user');
$this->load->library('form_validation');
//$this->load->library('form_validation', 'form_validation', true/false);
$this->form_validation->set_rules('username','Username','trim|required|xss_clean');
$this->form_validation->set_rules('password','Password','trim|required|xss_clean|callback_check_database');
if($this->form_validation->run() == FALSE)
{
redirect('login','refresh');
}
else
{
redirect('home','refresh');
}
}
function check_database($password)
{
$username = $this->input->post('username');
$this->load->model('user');
$result = $this->user->login($username,$password);
if($result)
{
$sess_array = array();
foreach($result as $row)
{
$sess_array = array('id'=>$row->id,'username'=>$row->username);
$this->session->set_userdata('logged_in',$sess_array);
}
return TRUE;
}
else {
$this->form_validation->set_message('check_database','Invalid username or password');
}
}
}
?>
Also where this form_validation.php
file is located.
form_validation.php
– rohitarora