Welcome Guest, Not a member yet? Register   Sign In
Forms and Databases (Best Practice)
#3

[eluser]Vicente Russo[/eluser]
Hi,

Thats what I do:
Code:
// Form sent        
$excluded = array('submit','i_agree_radio_button'); // Fields excluded from insert sql
$fieldnames = array( // Just example:
    'field_name_on_form' => 'field_name_on_table',
    'name' => 'name',
    'address_txt' => 'address'
);

$post_temp = array();
foreach($_POST as $index => $value) {
    if(!in_array($index,$excluded)) {
        $post_temp[$fieldnames[$index]] = $this->input->post($index);                    
    }
}

$this->db->insert('table_name', $post_temp);

But its possible to fill the $fieldnames array automatically, and if you put this on a model, ou just have to mess in one place


Messages In This Thread
Forms and Databases (Best Practice) - by El Forum - 03-12-2009, 10:14 AM
Forms and Databases (Best Practice) - by El Forum - 03-12-2009, 08:24 PM
Forms and Databases (Best Practice) - by El Forum - 03-13-2009, 06:30 AM
Forms and Databases (Best Practice) - by El Forum - 03-13-2009, 08:50 AM
Forms and Databases (Best Practice) - by El Forum - 03-13-2009, 10:15 PM



Theme © iAndrew 2016 - Forum software by © MyBB