Welcome Guest, Not a member yet? Register   Sign In
Official Blog Tutorial: db->insert insert error with $_POST
#1

[eluser]php-zbatev[/eluser]
hi,

I followed the blog tutorial and i am almost through but I'm have this problem with the
given insert statement:

function comment_insert()
{
$this->db->insert('comments',$_POST);
redirect('blog/comments/'.$_POST['entry_id']);
}
---------------------------------------------------------------------------------------
and ended up with this error:

An Error Was Encountered

Error Number: 1054

Unknown column 'Submit_Comment' in 'field list'

INSERT INTO `comments` (`entry_id`, `body`, `author`, `Submit_Comment`)
VALUES ('1', 'comment nako ni', 'z', 'Submit Query')
---------------------------------------------------------------------------------------
the Submit Comment is a submit button:
<p>&lt;input type="submit" name="Submit Comment"/&gt;</p>

I think that the error was triggered by $this->db->insert('comments',$_POST); but my question is why did it work in the vid tutorial, where do you think did I miss out?
#2

[eluser]php-zbatev[/eluser]
never mind, I got it myself again, I was not suppose to give the submit type input a name so it wouldn't hold a variable to be captured by the $_POST, let me show you why:

old(messed up) code:
<p>&lt;input type="submit" name="Submit Comment"&gt;</p>
new corrected code:
<p>&lt;input type="submit" value="Submit Comment"&gt;</p>

silly, silly me... eheheheh... maybe I just had too much reading, i've been trying to catch up with you guys.

:-)
#3

[eluser]optimal[/eluser]
That's a nice catch!
#4

[eluser]Unknown[/eluser]
Thanks a lot for this post.




Theme © iAndrew 2016 - Forum software by © MyBB