CodeIgniter Forums
Error when inserting from $_POST with Active Record - 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: Error when inserting from $_POST with Active Record (/showthread.php?tid=23666)



Error when inserting from $_POST with Active Record - El Forum - 10-19-2009

[eluser]Buso[/eluser]
$this->db->insert('comments',$_POST);

I get this:
>> Unknown column 'submit' in 'field list'
>> INSERT INTO `comments` (`user_name`, `email`, `body`, `submit`, `article_id`, `date`) VALUES ('aa', 'ff', 'aaa', 'Post!', '2', 1255932082)

Its trying to insert the submit field =S, and even worse, its trying to insert article_id as a string.. What can I do??


Error when inserting from $_POST with Active Record - El Forum - 10-19-2009

[eluser]rogierb[/eluser]
Hey there,

1: RTFM, there is a thing called the user_guide
2: NEVER everr use $_POST to insert, always clean up your vars.
3: remove the submit field/button from your form(rename it, but much much better would be to do point 2).
4: Article_id is not inserted as a string just because there a quotes around it. It will still be processed as an integer.


Error when inserting from $_POST with Active Record - El Forum - 10-19-2009

[eluser]Buso[/eluser]
[quote author="rogierb" date="1255952395"]Hey there,

1: RTFM, there is a thing called the user_guide
[/quote]
I've read it, thanks

Quote:2: NEVER everr use $_POST to insert, always clean up your vars.
You are right, i just wanted to try this active record thing.

Quote:3: remove the submit field/button from your form(rename it, but much much better would be to do point 2).
how? rename it to what?

Quote:4: Article_id is not inserted as a string just because there a quotes around it. It will still be processed as an integer.
ok


Error when inserting from $_POST with Active Record - El Forum - 10-19-2009

[eluser]rogierb[/eluser]
3: hmm error on my side, I guess you are using form_button(). This generates a button with a 'name'. Just use a custom html button without the name element. But like I said, don't use $_POST, Then you don't have problem.


Error when inserting from $_POST with Active Record - El Forum - 10-19-2009

[eluser]daparky[/eluser]
[quote author="rogierb" date="1255952395"]Hey there,

1: RTFM, there is a thing called the user_guide
2: NEVER everr use $_POST to insert, always clean up your vars.
3: remove the submit field/button from your form(rename it, but much much better would be to do point 2).
4: Article_id is not inserted as a string just because there a quotes around it. It will still be processed as an integer.[/quote]

How would you go about point 2?


Error when inserting from $_POST with Active Record - El Forum - 10-19-2009

[eluser]pistolPete[/eluser]
[quote author="daparky" date="1255991267"]How would you go about point 2?[/quote]
http://ellislab.com/codeigniter/user-guide/libraries/input.html