Welcome Guest, Not a member yet? Register   Sign In
why is this code failing?

(This post was last modified: 07-01-2020, 04:03 AM by richb201.)

I am trying to create an array that I will use to "insert" 2 fields into a table. I keep two important fields in a session variable. I want to insert them into a mySQL table. There seems to be a problem with the userdata('campaign'). Why is that?

$data = array(
    'email' => $this->session->userdata('userid'),
    'campaign' => '$this->session->userdata('campaign')

$this->db->insert($file_name, $data);

and I get this:
Type: ParseError

Message: syntax error, unexpected 'campaign' (T_STRING), expecting ')'

Filename: /app/application/libraries/Image_CRUD.php
Line Number: 368
proof that an old dog can learn new tricks

As error says it is a SYNTAX error.
Remove quote character before $this

(This post was last modified: 07-02-2020, 05:19 AM by richb201.)

Shy Thanks. How stupid of me. What I am really trying to do is add a few more fields into the table.

      $insert = array($this->url_field => $file_name);
      array_push($insert,'email => ' . $this->session->userdata('userid'));  <<trying to add two more fields before doing the insert
      array_push($insert,'campaign =>' .  $this->session->userdata('campaign'));
      $this->ci->db->insert($this->table_name, $insert);

This is failing with "call to a member function userdata() on null". So it seems that my image_CRUD.php module (which is in libraries) cannot load the session data. I tried adding $this->load->library('session'); to the Constructor in image_CRUD.php  but that fails. Since session is related to cookies, I figure that won't work either.  I tried a call (within image_CRUD.php) to $campaign= $this->session->userdata('campaign'); but this returns an error "Call to a member function userdata() on null". Any idea how to fix this? 

The problem is that I need to get those two variables, email and campaign into two  columns in the database record and can't seem to get them transferred to a different module. Any idea how to do this? 

also, where did the docs for CI 3 go??
proof that an old dog can learn new tricks

If you have CI 3 the docs come with it only the developer download needs them complied.

Go to user_guide and click on index.html theirs your docs.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )

If you are outside of context of a controller or a model, try this:


But it would be preferable not to desperse usage of the session library within modules, code would become hardly testable, it would be better you to read this data form a controller and pass it to a model.

I ended up getting his $_SERVER[email]. I had no idea that it we be there and just stumbled onto it. Re
proof that an old dog can learn new tricks

I managed to get it working using $_SERVER[email]. That variable is available in the other module. Works great thx.
proof that an old dog can learn new tricks

Theme © iAndrew 2016 - Forum software by © MyBB