yddib Posted September 8, 2008 Share Posted September 8, 2008 I am trying to post comments to the database. This is the code for the form: <!--DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"--> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> <head> <title> Comments </title> <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" /> <meta name="description" content="description goes here" /> <meta name="keywords" content="keywords,goes,here" /> <link rel="stylesheet" href="style1.css" type="text/css" /> <!--[if IE 6]> <link rel="stylesheet" href="fix.css" type="text/css" /> <![endif]--> </head> <body> <form name="myForm" action="testin.php" method="post"> <br /> <br /> <b>Comment</b> <br/> <br /> <textarea name="comment" cols="40" rows="10" /> </textarea> <br /><br /> <input type="reset" value="Reset" /> <input type="submit" value="Send" /> </form> </body> </html> This is the code for the testin.php: <html> <head> </head> <body> <?php mysql_connect("host", "username", "pass") or die(mysql_error()); //connects to the blacknight server mysql_select_db("database"); //selects the database called 4grads $comment=$_POST['comment']; mysql_query("INSERT INTO comments (comment) values ('$comment')"); echo "comment added successfully. well done."; ?> </body> </html> The text echoes but it doesn't enter the database. I can't see why! Any suggestions? Link to comment https://forums.phpfreaks.com/topic/123280-solved-values-into-database/ Share on other sites More sharing options...
Adam Posted September 8, 2008 Share Posted September 8, 2008 try replacing the query line with this: mysql_query("INSERT INTO comments (comment) values ('{$comment}')") or die(mysql_error()); Link to comment https://forums.phpfreaks.com/topic/123280-solved-values-into-database/#findComment-636644 Share on other sites More sharing options...
yddib Posted September 8, 2008 Author Share Posted September 8, 2008 Thanks for the quick response but the same thing happened. Text echoed but no value in the database. Link to comment https://forums.phpfreaks.com/topic/123280-solved-values-into-database/#findComment-636647 Share on other sites More sharing options...
revraz Posted September 8, 2008 Share Posted September 8, 2008 echo $comment and see if it's empty. You also don't have any error checking so why wouldn't the text echo? Link to comment https://forums.phpfreaks.com/topic/123280-solved-values-into-database/#findComment-636648 Share on other sites More sharing options...
gaza165 Posted September 8, 2008 Share Posted September 8, 2008 $comment = $_POST['comment']; $result = mysql_query("INSERT INTO comments (comment) values ('$comment')"); echo "comment added successfully. well done."; ?> try that... Link to comment https://forums.phpfreaks.com/topic/123280-solved-values-into-database/#findComment-636652 Share on other sites More sharing options...
revraz Posted September 8, 2008 Share Posted September 8, 2008 Why, it's the same thing as his. You didn't do any error checking either. Link to comment https://forums.phpfreaks.com/topic/123280-solved-values-into-database/#findComment-636655 Share on other sites More sharing options...
Adam Posted September 8, 2008 Share Posted September 8, 2008 i was going to say pretty much what they said... try: $comment = $_POST['comment']; $query = mysql_query("INSERT INTO comments (comment) VALUES ('{$comment}')"); if (!$query) { print 'MySQL Error: ' . mysql_error(); } else { print 'Comment: <strong>"' .$comment. '"</strong> entered successfully...'; } Link to comment https://forums.phpfreaks.com/topic/123280-solved-values-into-database/#findComment-636658 Share on other sites More sharing options...
gaza165 Posted September 8, 2008 Share Posted September 8, 2008 $comment = $_POST['comment']; $result = mysql_query("INSERT INTO comments (comment) values '$comment' "); echo "comment added successfully. well done."; ?> that should work.... no need to do error checking for such a simple question. you dont need the () around the variable Link to comment https://forums.phpfreaks.com/topic/123280-solved-values-into-database/#findComment-636660 Share on other sites More sharing options...
yddib Posted September 8, 2008 Author Share Posted September 8, 2008 Thanks for all the comments. The $result made it work!! Thank you so much!! It was wrecking my head!! Link to comment https://forums.phpfreaks.com/topic/123280-solved-values-into-database/#findComment-636661 Share on other sites More sharing options...
revraz Posted September 8, 2008 Share Posted September 8, 2008 Say what? What do you mean no need to do error checking? Show the guy how to do it right the first time. Teaching bad habbits is just wrong. Quote that should work.... no need to do error checking for such a simple question. you dont need the () around the variable Link to comment https://forums.phpfreaks.com/topic/123280-solved-values-into-database/#findComment-636664 Share on other sites More sharing options...
gaza165 Posted September 8, 2008 Share Posted September 8, 2008 I did show him how to do it right... it worked didnt it?? Link to comment https://forums.phpfreaks.com/topic/123280-solved-values-into-database/#findComment-636667 Share on other sites More sharing options...
Adam Posted September 8, 2008 Share Posted September 8, 2008 Say it didnt work one time though, he or the user won't know... Also the ()'s may not be required for it to work, but it's the right way to do it... as revraz says bad habbits... Link to comment https://forums.phpfreaks.com/topic/123280-solved-values-into-database/#findComment-636673 Share on other sites More sharing options...
gaza165 Posted September 8, 2008 Share Posted September 8, 2008 Good point guys... I will realise the error of my ways!! Link to comment https://forums.phpfreaks.com/topic/123280-solved-values-into-database/#findComment-636676 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.