![]() |
CI2: data validation before inserting it in DB - 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: CI2: data validation before inserting it in DB (/showthread.php?tid=32478) |
CI2: data validation before inserting it in DB - El Forum - 07-24-2010 [eluser]diostm[/eluser] Hello, I'm just get started with CI(CI2) and i created simple newsletter-webapp. But i'm not sure about my validation: Code: $this->form_validation->set_rules( Web form, from which i sent data: Code: <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');?> Table description in database: Code: CREATE TABLE `cms`.`news` ( Do i forgot something to check? CI2: data validation before inserting it in DB - El Forum - 07-24-2010 [eluser]pickupman[/eluser] What if you change: Code: $this->load->view('news_inserted', $this->data); To Code: $this->db->insert('news', $_POST); You may find it useful to do a Code: foreach($_POST as $key => $value){ As a bonus add this to your controller constructor Code: $this->output->enable_profiler(TRUE); // get all the CI goodness CI2: data validation before inserting it in DB - El Forum - 07-25-2010 [eluser]diostm[/eluser] Hm, thanks, but i mean, is it enough to control with a xss_clean function those params before inserting it in DB. Will it be enough when i want to get some data from DB (selecting it) or there have to be some more extra validations(for example with mysql_real_esacpe_string or with its wrapper in CI $this->db->escape() or $this->db->escape_str()) ? CI2: data validation before inserting it in DB - El Forum - 07-25-2010 [eluser]pickupman[/eluser] Well, with any app, you don't want to assume a user is feeding you something naughty. Basically any input that you can't typecast like bool or int, you will want to run through xss_clean. The $this->db->set() will make your queries safe. If you you the active record syntax for doing your queries, CI will take care of the security stuff for you. |