CodeIgniter Forums
Ignore submit button when inserting with Active Record - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21)
+--- Thread: Ignore submit button when inserting with Active Record (/showthread.php?tid=21168)



Ignore submit button when inserting with Active Record - El Forum - 08-01-2009

[eluser]rebellion[/eluser]
Hi

I'm inserting a comment from into a database table using Active Record, but when I submit the form, I get the following error:

Unknown column 'submit' in 'field list'.

Can I get CodeIgniter to ignore the submit button value? (The submit button is called 'submit').


Ignore submit button when inserting with Active Record - El Forum - 08-01-2009

[eluser]Eric Barnes[/eluser]
I imagine you are not setting an array and instead using the post array. I always do it like this:
Code:
$author = $this->input->post('comment_author', TRUE);
$email = $this->input->post('comment_author_email', TRUE);
$comment = $this->input->post('comment_content', TRUE);
$data = array(
                'comment_article_ID' => $this->input->post('comment_article_ID', TRUE),
                'comment_author' => $author,
                'comment_author_email' => $email,
                'comment_content' => $comment,
                'comment_author_IP' => $this->input->ip_address()
            );
$this->db->insert('comments', $data);

This also gives you the ability to check the data submitted and do any processing on it. Which you should also be using the form validation class.


Ignore submit button when inserting with Active Record - El Forum - 08-01-2009

[eluser]Armchair Samurai[/eluser]
Use unset()
Code:
/* In your model */

function enter_data($arr)
{
    unset($arr['submit']);

    $this->db->set($arr);
    $this->db->insert('foobar');
}