Page 1 of 1

MySQL Syntax Error

Posted: Sun Sep 05, 2010 6:30 am
by Darkmantle
I am getting this error:

"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 'leave (Name, Reason, DueDate) VALUES ('Test','Test','02-02-2010')' at line 1"

Yet the code I am using is correct, as I use the exact same syntax in many other pages, and it works fine! Here is my code:

Code: Select all

<?php
include('connect.php');

$leave = "INSERT INTO leave (Name, Reason, DueDate) VALUES ('$_POST[Name]','$_POST[Reason]','$_POST[Due]')";

if (!mysql_query($leave))
  {
  die('Error: ' . mysql_error());
  }

header("location:home.php");

mysql_close();
?>

Re: MySQL Syntax Error

Posted: Sun Sep 05, 2010 11:13 am
by McInfo
LEAVE is a reserved word in MySQL. Change the table name or use backticks (`):

Code: Select all

SELECT `field` FROM `table`

Re: MySQL Syntax Error

Posted: Sun Sep 05, 2010 11:18 am
by Darkmantle
McInfo wrote:LEAVE is a reserved word in MySQL. Change the table name or use backticks (`):

Code: Select all

SELECT `field` FROM `table`
Thank you so much! You won't believe how many so-called PHP coders didn't know the answer to that x.X