I have the following method in my verify_loginscontroller:
function checkLogInInfo() {
if ($_POST) {
$v = $this->input->post('user_id');
$vldata['password'] = $this->input->post('password');
$query1 = $this->db->query("SELECT e.id FROM user u LEFT JOIN employee e ON u.user_id = e.id WHERE e.emp_id = '$v' ")->result_array();
if (empty($query1)) {
$this->session->set_flashdata('message', 'Invalid ID or Password');
redirect('verify_logins/index');
} else {
$vldata = array();
$vldata['user_id'] = $query1[0]['id'];
$temp = $vldata['user_id'];
$query2 = $this->db->query("SELECT e.emp_name FROM user u LEFT JOIN employee e ON u.user_id = e.id WHERE e.id ='$temp' ")->result_array();
$vldata['user_name'] = $query2[0]['emp_name'];
$this->session->set_userdata($vldata['user_name']);
redirect('admin_logins/index');
}
} else {
redirect('verify_logins/index');
}
}
The above method checks my login data and logs in to the home page of my application.
Now I have another controller named admin_logins with the following method:
public function index() {
$data["message"] = $this->session->flashdata('message');
$data["user_name"] = $this->session->userdata($vldata['user_name']);
$this->load->view('admin_logins/index', $data);
}
The above method loads the home page of my application.
I'm trying to load the username of the logged in user in the home page. I'm trying to pass the username from method checkLogInInfo() of controller verify_logins() to method index() of controller admin_logins() by using session, but can't figure out the right way to do it. I can guess that I have some syntax problem in my index() method of the controller. I need help regarding the correct syntax and way to do it.
The portion of my view page where I'm trying to display the username is:
<p class="f-right">User: <strong><?php if(isset($user_name)){echo "Welcome, ".$user_name;} ?></strong></p>
And the error I'm getting is this:
A PHP Error was encountered
Severity: Notice
Message: Undefined variable: vldata
P.S. I've loaded the session library in both controllers.