![]() |
If user ID exists in database, UPDATE. Otherwise, INSERT (HELP) - 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: If user ID exists in database, UPDATE. Otherwise, INSERT (HELP) (/showthread.php?tid=55662) Pages:
1
2
|
If user ID exists in database, UPDATE. Otherwise, INSERT (HELP) - El Forum - 11-05-2012 [eluser]Barwick[/eluser] Okay, I got the below to write to the database. However, as you can see, I'm not passing any of my variables...how can I accomplish this? ALSO, if I change the number values, so example change 30 to 45, it doesn't update the database as it should - or let me phrase, how I want it too. Code: public function add_subscription() If user ID exists in database, UPDATE. Otherwise, INSERT (HELP) - El Forum - 11-05-2012 [eluser]Barwick[/eluser] [quote author="Barwick" date="1352173316"]Okay, I got the below to write to the database. However, as you can see, I'm not passing any of my variables...how can I accomplish this? ALSO, if I change the number values, so example change 30 to 45, it doesn't update the database as it should - or let me phrase, how I want it too. Code: public function add_subscription() Okay, i figured out the update issue...I had ON DUPLICATE KEY UPDATE id=34...which is the primary key that's causing the duplicate...needed to specify what the duplicate record was going to replace. Which in this case is the subscription. So I changed that. How do I enter in the array of variables into this query though?? Anyone?? If user ID exists in database, UPDATE. Otherwise, INSERT (HELP) - El Forum - 11-06-2012 [eluser]Narf[/eluser] Your update() method has 2 errors: 1. You're not passing the user ID to where(): Code: $this->db->where('id'); // your code 2. You're comparing num_rows() to the user ID (as CroNiX already pointed out) - num_rows() returns the number of rows selected, not a column's value. |