Update and checking - 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: Update and checking (/showthread.php?tid=1781) |
Update and checking - El Forum - 06-26-2007 [eluser]VivaUkraine[/eluser] How to ensure that updating was succesfull? i've a method: Code: function update_news($id){ how can i check was the data updated and if no to output some error message? Update and checking - El Forum - 06-26-2007 [eluser]woopsicle[/eluser] hi, use $this->db->affected_rows() i.e. Code: if ($this->db->affected_rows() >= 1) Update and checking - El Forum - 06-26-2007 [eluser]marcoss[/eluser] [quote author="VivaUkraine" date="1182910116"]How to ensure that updating was succesfull? i've a method: Code: function update_news($id){ how can i check was the data updated and if no to output some error message?[/quote] $this->db->update returns true if updated, so just check on that. Code: function update_news($id){ btw, don't use raw $_POST to insert data directly into the database, use (at least) CI Input library instead. Update and checking - El Forum - 06-28-2007 [eluser]VivaUkraine[/eluser] [quote author="marcoss" date="1182941845"] btw, don't use raw $_POST to insert data directly into the database, use (at least) CI Input library instead.[/quote] hmmm what do you mean? Update and checking - El Forum - 06-28-2007 [eluser]thunder uk[/eluser] The $_POST array *could* contain something nasty that screws up your database (or worse). So, instead, get your POSTed values into variables that are nice and clean and free from nasties. eg $title = $this->db->escape($this->input->post('newstitle')); $body = $this->db->escape($this->input->post('newsbody')); This still isn't foolproof since some of the bad guys know how to use multibyte character encoding to bypass the above, but it's still a good bit safer than passing raw $_POST data |