Q: Errors For User Login Model Codeigniter I am getting a couple of errors for my user model in my parent function. Just trying to make it this way. if $user_query->num_rows and also my isset session user-data.
Fatal error: Cannot use isset() on the result of a function call (you can use "null !== func()" instead) in C:\xampp\htdocs\codeigniter-cms-1\admin\application\modules\backend\models\user\user_model.php on line 11
and
Parse error: syntax error, unexpected 'if' (T_IF) in C:\xampp\htdocs\codeigniter-cms-1\admin\application\modules\backend\models\user\user_model.php on line 15
private $user_id;
private $username;
private $permission = array();

public function __construct() {
parent::__construct();
if(isset($this->session->set_userdata('user_id')) { // Error

$user_query = $this->db->query("SELECT * FROM " . $this->input->post('db_prefix') . "user WHERE user_id = '" . (int)$this->session->userdata('user_id') . "' AND status = '1'")

if($user_query->num_rows == 1) { // Error
    $this->user_id = $user_query->row('user_id');
    $this->username = $user_query->row('username');
    $this->db->query("UPDATE " . $this->input->post('db_prefix') . "user SET ip = '" . $this->input->ip_address() "' WHERE user_id = '" . (int)$this->session->userdata('user_id') . "'");
    $user_group_query = $this->db->query("SELECT * FROM " . $this->input->post('db_prefix')  . "user_group WHERE user_group_id = '" . (int)$query->row('user_group_id') . "'");
    } else {
       $this->logout();
    }
  }
}

public function login($username, $password) {
    // Still Working On This Part
}

public function logout() {
    $this->session->unset_userdata('user_id');

    $this->user_id = '';
    $this->username = '';
}


A: you missed (.) in below line
change this code:
$this->db->query("UPDATE " . $this->input->post('db_prefix') . "user SET ip = '" . $this->input->ip_address() "' WHERE user_id = '" . (int)$this->session->userdata('user_id') . "'");

To
$this->db->query("UPDATE " . $this->input->post('db_prefix') . "user SET ip = '" . $this->input->ip_address()."' WHERE user_id = '" . (int)$this->session->userdata('user_id') . "'");

Update
private $user_id;
private $username;
private $permission = array();

public function __construct() {
parent::__construct();
if(isset($this->session->set_userdata('user_id'))) { // here you missed close bracket

$user_query = $this->db->query("SELECT * FROM  " . $this->input->post('db_prefix') . "user WHERE user_id = '" . (int)$this->session->userdata('user_id') . "' AND status = '1'")

if($user_query->num_rows() == 1) { // num rows is function
    $this->user_id = $user_query->row('user_id');
    $this->username = $user_query->row('username');
    $this->db->query("UPDATE " . $this->input->post('db_prefix') . "user SET ip = '" . $this->input->ip_address()."' WHERE user_id = '" . (int)$this->session->userdata('user_id') . "'");
    $user_group_query = $this->db->query("SELECT * FROM " . $this->input->post('db_prefix')  . "user_group WHERE user_group_id = '" . (int)$query->row('user_group_id') . "'");
    } else {
       $this->logout();
    }
  }
}

public function login($username, $password) {
    // Still Working On This Part
}

public function logout() {
    $this->session->unset_userdata('user_id');

    $this->user_id = '';
    $this->username = '';
}


A: you can not use isset function on the $this instance!
try the updated code bellow.;) and let'me know how is it ;)
private $user_id;
private $username;
private $permission = array();

public function __construct() {
parent::__construct();
if(!empty($this->session->set_userdata('user_id'))) { 

$user_query = $this->db->query("SELECT * FROM " . $this->input->post('db_prefix') . "user WHERE user_id = '" .$this->session->userdata('user_id') . "' AND status = '1'");

if($user_query->num_rows > 0) { 
    $this->user_id = $user_query->row('user_id');
    $this->username = $user_query->row('username');
    $this->db->query("UPDATE " . $this->input->post('db_prefix') . "user SET ip = '" . $this->input->ip_address() "' WHERE user_id = '" . (int)$this->session->userdata('user_id') . "'");
    $user_group_query = $this->db->query("SELECT * FROM " . $this->input->post('db_prefix')  . "user_group WHERE user_group_id = '" . (int)$query->row('user_group_id') . "'");
    } else {
       $this->logout();
    }
  }
}

public function login($username, $password) {
    // Still Working On This Part
}

public function logout() {
    $this->session->unset_userdata('user_id');

    $this->user_id = '';
    $this->username = '';
}

