I'm just new using codeIgniter and I wanted to create a simple login with sign up and session.
Here's my code...
<?php if(!defined('BASEPATH')) exit('No direct script access allowed');
class LoginVerify extends CI_Controller {
function __construct() {
parent::__construct();
$this->load->model('userModel', '', TRUE);
}
function index() {
$this->load->library('form_validation');
$this->form_validation->set_rules('username', 'Username', 'trim|required');
$this->form_validation->set_rules('password', 'Password', 'trim|required|callback_this_database');
if($this->form_validation->run()==FALSE) {
$this->load->view('login_view');
}
else {
redirect('home', 'refresh');
}
}
function this_database($password) {
$username=$this->input->post('username');
$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(this_database, 'Invalid username or password');
return FALSE;
}
}
}
?>
I don't know why I'm still receiving error when trying to run this program.