CodeIgniter Forums
Exclude insertion in the database.....($this->db->insert($table, $_POST)) - 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: Exclude insertion in the database.....($this->db->insert($table, $_POST)) (/showthread.php?tid=49690)



Exclude insertion in the database.....($this->db->insert($table, $_POST)) - El Forum - 02-28-2012

[eluser]kobeddon[/eluser]
when using $this->db->insert($table, $_POST); it automatically inserts all input forms in the table......my question is, is there a way to exclude an input type? lets say i have a hidden type, that i only need for my controller, and not necessarily needed in the db


....this is my first post and fairly new to CI, looking forward for the replies


Exclude insertion in the database.....($this->db->insert($table, $_POST)) - El Forum - 02-29-2012

[eluser]PhilTem[/eluser]
Do
Code:
unset($_POST['input_key_to_unset']);
$this->db->insert($table, $_POST);


which is the easiest way. Of course you can have an array representing all fields of your table and then clean the $_POST with

Code:
$cleaned_post = array_intersect($table_fields, $_POST);

assuming you have same names for both the table-fields as well as the input-fields.
Refer to http://php.net/manual/en/function.array-intersect-key.php for more info.


Exclude insertion in the database.....($this->db->insert($table, $_POST)) - El Forum - 02-29-2012

[eluser]kobeddon[/eluser]
thanks for the reply... i think ill try that unset method creating the array would take too long as the table is pretty big