Jump to content

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.