Move this line from controller to view:
PHP Code:
$user_id = $this->session->userdata('user_id');
Or put the $user_id in an array which is passed to the view.
Controller:
PHP Code:
$data['user_id'] = $this->session->userdata('user_id');
$this->load->view('createadvert', $data);
In both cases, the $user_id variable will be available in the view.