0

Am trying to allow users to insert their comments in my website and it shows me this error

the error shown is Error: 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 ''id', 'name', 'email', 'website', comment, timestamp, articleid) VALUE' at line 1

Error: 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 ''id', 'name', 'email', 'website', `comment`, `timestamp`, `articleid`) VALUE' at line 1
<?


if( $_POST )
{
  $con = mysql_connect("localhost","iluxcoke_myuser","qwert2012");
    
  if (!$con)
  {
    die('Could not connect: ' . mysql_error());
  }
 
  mysql_select_db("iluxcoke_inmoti6_mysite", $con);

  $users_name = $_POST['name'];
  $users_email = $_POST['email'];
  $users_website = $_POST['website'];
  $users_comment = $_POST['comment'];

  $users_name = mysql_real_escape_string($users_name);
  $users_email = mysql_real_escape_string($users_email);
  $users_website = mysql_real_escape_string($users_website);
  $users_comment = mysql_real_escape_string($users_comment);


$sql = "SELECT * FROM `comments` LIMIT 0, 30 ";
   $sql= "INSERT INTO `comments`('id', 'name', 'email', 'website',
    `comment`, `timestamp`, `articleid`) VALUES ( id, '$users_name',
 '$users_email', '$users_website', '$users_comment',
  'CURRENT_TIMESTAMP ');";
        
if (!mysql_query($sql,$con)) {
die('Error: ' . mysql_error()); 
} 
 //mysql_query($sql)

  echo "<h2>Thank you for your Comment!</h2>";

  mysql_close($con);
}
?>
  • Welcome to StackOverflow. Please take a minute to take the [tour] and have a look at the [help] center. Also, please, do NOT use `mysql` functions any more! use PDO or Mysqli instead! – Burki Nov 27 '15 at 13:05

1 Answers1

0

Change single quotes to backticks on id, name, email and website. Also CURRENT_TIMESTAMP should not be enclosed in single quotes as it is a MySQL property.

INSERT INTO `comments` (`id`, `name`, `email`, `website`,
`comment`, `timestamp`, `articleid`) VALUES ( $id, '$users_name', '$users_email', '$users_website', '$users_comment', CURRENT_TIMESTAMP);
Samir Selia
  • 7,007
  • 2
  • 11
  • 30