Jump to content

[SOLVED] Can't figure why my form is not inserting...


pneudralics

Recommended Posts

<?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>

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) {

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

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 :)

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.