I received an error:
A PHP Error was encountered
Severity: Notice
Message: Undefined variable: data
Filename: controllers/c_verifylogin.php
Line Number: 17
This is the filename that has an error:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class C_verifyLogin extends CI_Controller {
function __construct() {
parent::__construct();
//load session and connect to database
$this->load->model('m_login','login',TRUE);
$this->load->helper(array('form', 'url','html'));
$this->load->library(array('form_validation','session'));
}
function index() {
$this->form_validation->set_rules('studentid', 'studentid', 'trim|required|xss_clean');
$this->form_validation->set_rules('password', 'password', 'trim|required|xss_clean|callback_check_database');
if($this->form_validation->run() == FALSE) {
$this->load->view('v_login');
} else {
//Go to private area
redirect(base_url('c_home'), 'refresh');
}
}
function check_database($password) {
//Field validation succeeded. Validate against database
$studentid = $this->input->post('studentid');
//query the database
$result = $this->login->login($studentid, $password);
if($result) {
$sess_array = array();
foreach($result as $row) {
//create the session
$sess_array = array('studentid' => $row->studentid);
//set session with value from database
$this->session->set_userdata('logged_in', $sess_array);
}
return TRUE;
} else {
//if form validate false
$this->form_validation->set_message('check_database', 'Invalid username or password');
return FALSE;
}
}
}
/* End of file c_verifylogin.php */
/* Location: ./application/controllers/c_verifylogin.php */
and this is the view which the data is passed
<!DOCTYPE html>
<html>
<head>
<title>Simple Login with CodeIgniter</title>
</head>
<body>
<h1>Simple Login with CodeIgniter</h1>
<?php echo validation_errors(); ?>
<?php echo form_open('c_verifylogin/index');
echo form_label("StudentID: ");
echo form_input("studentid");
echo br();
echo form_label("Password: ");
echo form_password("password");
echo br();
echo form_submit("","Login");
echo form_close();
?>
</body>
</html>
I've been searching for the problem for hours, and I still don't know what's wrong with it. Can someone help?