getting property of non-object error |
Severity: Notice --> Trying to get property of non-object
Here is the code PHP Code: function company_update($row) This code seems to run fine on my windows apache and also on my AWS Lightsail server. Why would it be different on Ubuntu? I am thinking that I copied the campaigns2 table from the windows PC. Perhaps things got out of sync? ![]()
proof that an old dog can learn new tricks
The $row variable you're passing to the function, is a numeric value, right?
PHP Code: $campaign = $row->company_division; I think you have to change it to this: PHP Code: $query=$this->db->get_where('campaigns2',array('id'=>$row));
$row is actually the auto-increment (index) field from mysql. I am using GroceryCrud so when a user clicks on a row in my grid, GroceryCrud is sending the auto-inc field to company_update(). Is it an int? No, in php it is a $string. The problem is that I only have the auto-inc field, so I need to query the campaigns2 table to actually get the "real data". So I would think that $query->company_division would point at the company_data field in the table. But it doesn't work like that. I need to do some call to $results to get the actual fields.
So I added $q=$query->result(); and also $q[0]->company_division; I am still having issues. What really bothers me is that this works fine under Windows and also under Linux on AWS. Unless, of course I found an additional bug.
proof that an old dog can learn new tricks
How many results do you expect if you're pointing to an auto-increment field? Just one, right? Then, the result() function makes no sense. Just use row() to fetch the one and only record that can be found. Row() will return an object with the record, holding the fields as properties. Row_array() does the same, but then the result is an array instead of an object.
You don't describe what issue you still have. Where does it go wrong? To do some kind of debugging, use print_r() to visualize the result from the query. PHP Code: echo '<pre>'; You can do this in your controller or model.
I changed the code to:
$userid=$this->session->userdata('userid'); $query=$this->db->get_where('campaigns2',array('id'=>$row)); $q=$query->row(); $campaign = $q->company_division; $this->session->userdata('campaign')-> $q->$campaign; <<<<this is line 723 But I am still getting this error: <h4>A PHP Error was encountered</h4> <p>Severity: Notice</p> <p>Message: Trying to get property of non-object</p> <p>Filename: controllers/Configure.php</p> <p>Line Number: 723</p>
proof that an old dog can learn new tricks
What's the purpose of this line (723)?
PHP Code: $this->session->userdata('campaign')-> $q->$campaign; It does not assign or output a value. If the statement has any value at all, nothing happens with it. It would make sense if you would store a value into the session variable, e.g.: PHP Code: $this->session->campaign = $campaign;
Everything in a session is only for "this" user, so "userdata()" is not a special place where data is stored.
$this->session->userdata() is only for backwards compatibility. In previous versions of CI, you had to add data to the session like this: PHP Code: $this->session->set_userdata('some_name', 'some_value'); But from version 3.x you can do this: PHP Code: $this->session->some_name = some_value; or even: PHP Code: $_SESSION['some_name'] = some_value; To retrieve data from the session, you can do the same thing: PHP Code: $some_name = $this->session->userdata( 'some_name'); It's explained here: https://www.codeigniter.com/userguide3/l...ssion-data |
Welcome Guest, Not a member yet? Register Sign In |