MySQL Syntax Error

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
Darkmantle
Forum Newbie
Posts: 3
Joined: Sun Sep 05, 2010 6:28 am

MySQL Syntax Error

Post 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();
?>
User avatar
McInfo
DevNet Resident
Posts: 1532
Joined: Wed Apr 01, 2009 1:31 pm

Re: MySQL Syntax Error

Post by McInfo »

LEAVE is a reserved word in MySQL. Change the table name or use backticks (`):

Code: Select all

SELECT `field` FROM `table`
Darkmantle
Forum Newbie
Posts: 3
Joined: Sun Sep 05, 2010 6:28 am

Re: MySQL Syntax Error

Post 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
Post Reply