CodeIgniter Forums

Full Version: Undefined index: member_id !!
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi;

Why do I get
Code:
A PHP Error was encountered

Severity: Notice

Message: Undefined index: member_id

Filename: views/header_view.php

Line Number: 53

This is line 53
PHP Code:
echo $c_items $this->model_auth->count_shopping_cart_items($this->session->userdata['logged_data']['member_id']); 

I thought it's because the session doesn't exist, so in controller I added this. Didn't make any difference!
PHP Code:
$session_data $this->session->userdata('logged_data');
$session_data['member_id'] = "";
$this->session->set_userdata("logged_data"$session_data); 

Cheers
Try first catching the session item and after that to use the key..
PHP Code:
$data $this->session->userdata('logged_data');
$member_id = isset($data['member_id']) ? $data['member_id'] : 0

echo 
$c_items $this->model_auth->count_shopping_cart_items($member_id); 
Even you can set if member_id == 0 then don't echo anything.. instead do something else (redirect to login etc..)

Notice:
$this->session->userdata - this is method .. you can't just use it as array $this->session->userdata['logged_data']['member_id']