1
votes

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.

3
in system/libraries you can get form_validation.phprohitarora
@rohitarora see the code block comment.Sven van Zoelen
@Nitish: please copy & paste all code in your controller from class creationVinoth Babu
Is there a problem with your callback function? Try commenting it out. If that works then post your callback function, the problem is in there.Rooneyl
@Rooneyl I commented out that line but its same error !Nitish

3 Answers

1
votes

Please move all this code from index() function to the constructor,

$this->load->helper(array('form', 'url'));
$this->load->model('user');
$this->load->library('form_validation');

Because you are using the form_validation library in check_database() function also.

It should work now. :)

1
votes

Can you put your login.php and home.php in your question?

i think you should use this

$this->load->view('login');

despite this

redirect('login','refresh');
0
votes

you have to call helper function form before you use form validation

$this->load->helper(array('form', 'url'));

use this before you call library of form validation