I’m returing session data from my database, but I’m unable to display the LastName attribute of my table, and I don’t know why because the FirstName returns sucessfully. I do have the LastName attribute in my database. my view is giving me the error:Message: Undefined index: Lastname // Filename: controllers/home.php
here is my model
Class Membership_model extends CI_Model
{
function __construct()
{
parent::__construct();
}
function validate_student($username,$password){
$this -> db -> select('Student_ID, Firstname,Lastname, password');
$this -> db -> from('Student');
$this -> db -> where('Student_ID = ' . "'" . $username . "'");
$this -> db -> where('password = ' . "'" . MD5($password) . "'");
$this -> db -> limit(1);
//If it is all correct
$query = $this -> db -> get();
if($query->num_rows() == 1){
return $query->result();
}else{
return false;
}
}
controller: home
class Home extends CI_Controller {
function __construct()
{
parent::__construct();
}
function index()
{
if($this->session->userdata('logged_in'))
{
$session_data = $this->session->userdata('logged_in');
$data['Firstname'] = $session_data['Firstname'];
$data['Lastname'] = $session_data['Lastname'];
$this->load->view('home_view', $data);
}
home view:
<h2>Welcome <?php echo $Lastname; ?>
print the session data
$session_data, update your question with that , the error is you have no index Lastname in$session_data['Lastname'];,form where you set the session data
logged_in, please update your question with that also