![]() |
insert problem - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: insert problem (/showthread.php?tid=39070) Pages:
1
2
|
insert problem - El Forum - 02-28-2011 [eluser]dianikol85[/eluser] Hi to all. i have the following. A short version of the actual code but it will give you the idea Code: class my_controller extends CI_Controller { So far so good. But when the $this->index(); is called it two rows in the db instead of one if i use redirect('my_controller/index') or if commenting out this line Code: //$this->index(); Does it happen to anyone else??? I dont want to use the redirect function beacause i also i pass a message to the index that the insert is success. insert problem - El Forum - 02-28-2011 [eluser]Cristian Gilè[/eluser] $message doesn't exist. It should be Code: $this->message The right code: Code: class my_controller extends CI_Controller { If you are not creating a base controller, change the controller name to something else. MY_ is a private keyword for codeigniter. Cristian Gilè insert problem - El Forum - 02-28-2011 [eluser]dianikol85[/eluser] i dont use MY_. i used it only for this example. I also hav $this->maessage, I misspellit when i wrote this post. The code is correct anyway. Any thoughts about this double insertation?? insert problem - El Forum - 02-28-2011 [eluser]AlunR[/eluser] [quote author="dianikol85" date="1298931397"]i dont use MY_. i used it only for this example. I also hav $this->maessage, I misspellit when i wrote this post. The code is correct anyway. Any thoughts about this double insertation??[/quote] Put the message in a SESSION Flash and call it back from there. No idea why it's running twice. I imagine there is a deeper problem somewhere else in the code. insert problem - El Forum - 02-28-2011 [eluser]Cristian Gilè[/eluser] Please, post the model code. Cristian Gilè insert problem - El Forum - 02-28-2011 [eluser]dianikol85[/eluser] The model is Code: function user_insert($user_array) The method where i do the post request is Code: function user_added() The index method is Code: function index() insert problem - El Forum - 02-28-2011 [eluser]Cristian Gilè[/eluser] I can't see any error in the code you provided. Hint: When you're doing "write" type queries (insert, update, etc.) you should use $this->db->affected_rows() to know the number of affected rows. Code: function user_insert($user_array) Cristian Gilè insert problem - El Forum - 02-28-2011 [eluser]dianikol85[/eluser] Thanks for tip, I'll use it from now on. Do you suggest to use session to store the message and then use redirect(). As i said before if i use this it works fine insert problem - El Forum - 02-28-2011 [eluser]Cristian Gilè[/eluser] In the user_added() method, what's after this piece of code ? Code: // Send the data to the user model to insert the user Is there something else ? Cristian Gilè insert problem - El Forum - 02-28-2011 [eluser]dianikol85[/eluser] Nothing else. Just that. This is thecode the user_added contains. if i comment out this line $this->index() the query will run once as it should be. I can't see any mistakes in index() method. This is pretty frustrating ![]() |