Model method not inserting data but gets called successfully - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5) +--- Forum: Model-View-Controller (https://forum.codeigniter.com/forumdisplay.php?fid=10) +--- Thread: Model method not inserting data but gets called successfully (/showthread.php?tid=62777) |
Model method not inserting data but gets called successfully - cirox - 08-25-2015 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)) PHP Code: if($this->ion_auth_model->update($id, $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!! RE: Model method not inserting data but gets called successfully - PaulD - 09-15-2015 If you set up a test on $this->ion_auth_model->update($id, $data) does it work? I would suspect that if your IF statement is being parsed as TRUE then something other than FALSE is being returned, perhaps an error message? Is your $data constructed with the right information? My first approach would be to validate the $data field, if that was as you intended it to be, is it what ion_auth expected (check the docs) or check the call works by itself. The fact that $this->ion_auth_model->changepassword is working does not say anything about your $this->ion_auth_model->update method. Hope you get it fixed, Best wishes, Paul. RE: Model method not inserting data but gets called successfully - lazyfox - 10-12-2015 (08-25-2015, 04:34 PM)cirox Wrote: Hey everyone, 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', ...); Hope it may help! RE: Model method not inserting data but gets called successfully - jaynarayan - 12-17-2015 Enable the profiler and inspect which SQL queries are being fired . |