pneudralics Posted May 22, 2009 Share Posted May 22, 2009 <?php $cookieid = $_COOKIE['id']; $postcomment = $_POST['postcomment']; if (isset($_POST['submitpostcomment'])) { if (!empty($_POST['postcomment'])){ $postcommentq = "INSERT INTO usercomments (from, to, comment, date, approve) VALUES ('$cookieid', '$getid', '$postcomment', NOW(), 'N')"; if (mysql_query($postcommentq)) { echo "<font color=\"red\">Comment posted. Waiting for approval.</font>"; } else { echo "<font color=\"red\">There was an issue posting the comment.</font>"; } } else { echo "<font color=\"red\">Post comment is empty.</font>"; } }//End isset submitpostcomment ?> <form action="comment.php" method="post"> Post Comment <br /> <textarea name="postcomment" cols="30" rows="10"> </textarea> <br /> <input type="submit" name="submitpostcomment" value="Submit" /> </form> Quote Link to comment https://forums.phpfreaks.com/topic/159262-solved-cant-figure-why-my-form-is-not-inserting/ Share on other sites More sharing options...
dennismonsewicz Posted May 22, 2009 Share Posted May 22, 2009 are you getting any errors? Also, where is $getid being set at? Quote Link to comment https://forums.phpfreaks.com/topic/159262-solved-cant-figure-why-my-form-is-not-inserting/#findComment-839949 Share on other sites More sharing options...
pneudralics Posted May 22, 2009 Author Share Posted May 22, 2009 No errors I just keep getting: There was an issue posting the comment. It also does not insert into the database. $getid = $_GET['id']; //Top of page Quote Link to comment https://forums.phpfreaks.com/topic/159262-solved-cant-figure-why-my-form-is-not-inserting/#findComment-839954 Share on other sites More sharing options...
dennismonsewicz Posted May 22, 2009 Share Posted May 22, 2009 try echoing out your SQL command echo $postcommentq; Quote Link to comment https://forums.phpfreaks.com/topic/159262-solved-cant-figure-why-my-form-is-not-inserting/#findComment-839956 Share on other sites More sharing options...
jackpf Posted May 22, 2009 Share Posted May 22, 2009 And put or die(mysql_error()); after your query/connections. Quote Link to comment https://forums.phpfreaks.com/topic/159262-solved-cant-figure-why-my-form-is-not-inserting/#findComment-839957 Share on other sites More sharing options...
pneudralics Posted May 22, 2009 Author Share Posted May 22, 2009 No errors. echo shows data are in the value section. Quote Link to comment https://forums.phpfreaks.com/topic/159262-solved-cant-figure-why-my-form-is-not-inserting/#findComment-839959 Share on other sites More sharing options...
BobcatM Posted May 22, 2009 Share Posted May 22, 2009 The only thing I can see just make sure the usercomments table is the right DB table, and all the fields are correct. Quote Link to comment https://forums.phpfreaks.com/topic/159262-solved-cant-figure-why-my-form-is-not-inserting/#findComment-839962 Share on other sites More sharing options...
dennismonsewicz Posted May 22, 2009 Share Posted May 22, 2009 try doing this to your postcomment var $postcomment = mysql_real_escape_string($_POST['postcomment']); Quote Link to comment https://forums.phpfreaks.com/topic/159262-solved-cant-figure-why-my-form-is-not-inserting/#findComment-839965 Share on other sites More sharing options...
jackpf Posted May 22, 2009 Share Posted May 22, 2009 If you put or die(mysql_error()); after your query and didn't get any errors then it must be inserting. Quote Link to comment https://forums.phpfreaks.com/topic/159262-solved-cant-figure-why-my-form-is-not-inserting/#findComment-839969 Share on other sites More sharing options...
pneudralics Posted May 22, 2009 Author Share Posted May 22, 2009 Tried the escape string nothing happened. This is how I displayed the error: if (mysql_query($postcommentq).mysql_error()) { echo "<font color=\"red\">Comment posted. Waiting for approval.</font>"; } Quote Link to comment https://forums.phpfreaks.com/topic/159262-solved-cant-figure-why-my-form-is-not-inserting/#findComment-839975 Share on other sites More sharing options...
dennismonsewicz Posted May 22, 2009 Share Posted May 22, 2009 Try this $postcommentq = mysql_query("INSERT INTO usercomments (from, to, comment, date, approve) VALUES ('$cookieid', '$getid', '$postcomment', NOW(), 'N')")or die(mysql_error()); if ($postcommentq) { Quote Link to comment https://forums.phpfreaks.com/topic/159262-solved-cant-figure-why-my-form-is-not-inserting/#findComment-839978 Share on other sites More sharing options...
pneudralics Posted May 22, 2009 Author Share Posted May 22, 2009 I get the following: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'from, to, comment, date, approve) VALUES ('31', '31', 'testtexttesttext' at line 1 Oh and I'm using the latest XAMPP Quote Link to comment https://forums.phpfreaks.com/topic/159262-solved-cant-figure-why-my-form-is-not-inserting/#findComment-839981 Share on other sites More sharing options...
Philip Posted May 22, 2009 Share Posted May 22, 2009 from and to are reserved words that needs to be surrounded by backticks. (I find it good practice to put backticks around all of the col/table names) $postcommentq = mysql_query("INSERT INTO `usercomments` (`from`, `to`, `comment`, `date`, `approve`) VALUES ('$cookieid', '$getid', '$postcomment', NOW(), 'N')")or die(mysql_error()); Also, make sure to clean the $cookieid/$getid variables Quote Link to comment https://forums.phpfreaks.com/topic/159262-solved-cant-figure-why-my-form-is-not-inserting/#findComment-839988 Share on other sites More sharing options...
dennismonsewicz Posted May 22, 2009 Share Posted May 22, 2009 XAMPP is a great program. Kudos KingPhillip -> I bow before thee Quote Link to comment https://forums.phpfreaks.com/topic/159262-solved-cant-figure-why-my-form-is-not-inserting/#findComment-839992 Share on other sites More sharing options...
pneudralics Posted May 22, 2009 Author Share Posted May 22, 2009 from and to are reserved words that needs to be surrounded by backticks. (I find it good practice to put backticks around all of the col/table names) $postcommentq = mysql_query("INSERT INTO `usercomments` (`from`, `to`, `comment`, `date`, `approve`) VALUES ('$cookieid', '$getid', '$postcomment', NOW(), 'N')")or die(mysql_error()); Also, make sure to clean the $cookieid/$getid variables Thanks. The backtick solved the problem. Quote Link to comment https://forums.phpfreaks.com/topic/159262-solved-cant-figure-why-my-form-is-not-inserting/#findComment-840326 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.