Welcome Guest, Not a member yet? Register   Sign In
Ignore submit button when inserting with Active Record
#1

[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').
#2

[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.
#3

[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');
}




Theme © iAndrew 2016 - Forum software by © MyBB