Welcome Guest, Not a member yet? Register   Sign In
Model method not inserting data but gets called successfully
#3

(08-25-2015, 04:34 PM)cirox Wrote: Hey everyone,

I am really having a hard time figuring out something that looks so strange.

Here is what I want to do: each time a user updates profile using the "update" method in ion_auth, I am logging user activity in the database in a table called "activity". I created a model with a method "log" that has two arguments: UserId and the ActivityMessage.

When I call this "log" method in the user controller 'changepassword' method, it works fine. It inserts the activity to the table. BUT when I call this method inside an if statement that updates user profile, the "log" method gets called successfully BUT never inserts data to the "activity" table. However, the auto-increment ID of the activity table gets incremented if I manually insert the row into the database. It looks like it inserts the row and deletes it automatically?

The following works (log method inserts data successfully):

PHP Code:
if ($this->ion_auth_model->changepassword($identity$current_password$password))
{
 
//log user activity
 
$this->activity_model->log($this->ion_auth->user()->row()->id'changed password.');
 
redirect('user/profile','refresh');

BUT the following will NOT insert data to database (however the log method gets called):


PHP Code:
if($this->ion_auth_model->update($id$data)) {
 
$this->activity_model->log($this->ion_auth->user()->row()->id'changed profile data.');
 
redirect('user/profile','refresh');

I even created a helper function to log user activity in the database, so I called the helper function inside the if($this->ion_auth_model->update($id, $data)) {..helper method here..} block, but STILL it did not populate the table. But if I call that function in the same controller in the ion_auth change password method, it successfully logs data.

Sorry for the long description. But I am really pulling my hair on this!! I tried tons of ways to find out why it does not work!

Please help!!

It will not insert any data to your database because you called the UPDATE method. Use the insert function in your model.



Code:
$data = array('field1' => 'value1', 'field2' => 'value2', ...);
$this->db->insert('tablename', $data);

Hope it may help!
Reply


Messages In This Thread
RE: Model method not inserting data but gets called successfully - by lazyfox - 10-12-2015, 07:55 PM



Theme © iAndrew 2016 - Forum software by © MyBB