
- You are not logged in. | Login
November 17, 2006 12:47 am
- tucansam
- Member


Help me put my Form information into my database
Hi I've got a form where people enter a name, email address and a comment to put unter my blog entries. I had someone help me setup a database on my webserver, and i've got the thing i need to put the information into the database, but it's not seem to be working right!
November 17, 2006 12:52 am
- phppat
- Member


Re: Help me put my Form information into my database
Hi there and welcome to the forum.
Could you show us the code for your form, and the code being used to add that form information into your database?
PHP monster
November 17, 2006 1:25 am
- tucansam
- Member


Re: Help me put my Form information into my database
thank you you're quick!
this is the form that shows up under my blog
<form name="add_comments" action="<?php echo $_SERVER['PHP_SELF'];?>" method="POST"> <input name="user" type="text" \><br \> <input name="email" type="text" \><br \> <textarea name="comment"></textarea> </form>
this is what he gave me to put the form into my database
insert into comments (name, email, comment) values ( $name, $email, $comments)
November 17, 2006 1:27 am
- tucansam
- Member


Re: Help me put my Form information into my database
so thats the code he gave me but it doesn't do anything.. i can type in a name, address and comments, but it doesn't do anything? shouldn't be there a button to submit?
November 17, 2006 2:00 am
- phppat
- Member


Re: Help me put my Form information into my database
That's a start.
Add this after the textarea and before the end of the form:
<input type="submit" \>
That will give you the button to submit the comment.
As for adding the form data to the database, it looks like your friend didn't give you all the code you need. Try this on for size:
$db_link = mysql_connect( "your_mysql_host", "mysql_user", "mysql_password" );
That will get you connected. Then, you'll need to pull the form data from the $_POST variable:
$user = $_POST['user']; $email = $_POST['email']; $comment = $_POST['comment'];
Then, add that to the database with this:
mysql_query("INSERT INTO comments (name, email, comment) VALUES ($user, $email, $comment);That will post the data into your database as you expected. Hope that helps!
PHP monster


