Welcome Guest, Not a member yet? Register   Sign In
active record and $_POST error...
#1

[eluser]JP X3M[/eluser]
CodeIgniter newbie here... ^__^

im having problems with the method in the video create a blog in 20 minutes...

why does the function

function comment_insert(){

$this->db->insert('comments',$_POST);

}

it wants to insert even the submit button... but naturally it will not be found on the database and so generates an error 1054

Unknown column 'Post_Comment' in 'field list'

thanks in advance.. im sorry for asking such noobish question,,, ^__^
#2

[eluser]ELRafael[/eluser]
[quote author="JP X3M" date="1190238735"]CodeIgniter newbie here... ^__^

im having problems with the method in the video create a blog in 20 minutes...

why does the function

function comment_insert(){

$this->db->insert('comments',$_POST);

}

it wants to insert even the submit button... but naturally it will not be found on the database and so generates an error 1054

Unknown column 'Post_Comment' in 'field list'

thanks in advance.. im sorry for asking such noobish question,,, ^__^[/quote]

hum... in the video, doesn't have name (name='Post_Comment') in the submitt button. :cheese:
but, for security reason, you need to validate the post that you received. Be carefull when you use $this->db->insert('table', $_POST);
#3

[eluser]Michael Wales[/eluser]
Yeah, I definitely would not just dump the $_POST array into that field. Here's what you should (and it will give you some practice working with CI!

1. Create an array named (I usually call it $insert) where each key is the name of a column in your record that corresponds to the value from the posted form.
2. Use Active Record to insert this array.

Here's a code example really quick - I've never watched the blog tutorial so I can't use the same fields but you'll get the idea:

Code:
$insert = array{'title' => $this->input->post('title'),
            'body' => $this->input->post('body'),
            'created_on' => now(),
            'user_id' => $this->session->userdata('id'));
if ($this->db->insert('posts', $insert)) {
  return TRUE;
} else {
  return FALSE;
}
#4

[eluser]JP X3M[/eluser]
thanks for the reply... ^__^ i was just trying it anyway...
i was just doing it step by step to familiarize with the environment... Smile
gonna try your idea right away!
#5

[eluser]Unknown[/eluser]
I ran into this same thing. I did follow the directions above, and it works perfectly. But what I'm kinda confused about is when I first followed the tutorial, things worked fine. The database would get updated, etc... But when I added FCKEditor to the mix, suddenly I got the error that he got. I understand the security issues, but I'm just not sure why that the error showed up only AFTER I changed the "body" field to include rich text. If anyone could shed some light on this it may prevent a problem I might run into at a later date. Afterall I'm trying to learn CI and this is perplexing to me Smile
#6

[eluser]Michael Wales[/eluser]
It's been awhile since I used FCKEditor, but I believe it dynamically generates some additional fields on your form (these are hidden from normal view). The error occurs when attempting to insert the $_POST array, these new-found fields are being insert as well. CI and MySQL go "wtf?" because those fields are not found in your database.
#7

[eluser]meovino[/eluser]
JP -- Glad I'm not the only one having this problem. Thought I was going nuts. Makes sense that the $_POST array would have the submit button in it. I just can't figure out how it works for Derek.
#8

[eluser]Negligence[/eluser]
Just do this...
Code:
unset($_POST['submit']);
... before you pass it along.




Theme © iAndrew 2016 - Forum software by © MyBB