Reputation: 419
I am getting this error from MySQL when inserting data into database:
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 (apply_date, leave_category, leave_type, from_date, to_date, reason, duty_' at line 1"
I have not received before(I made the same script a little over a week ago and never had this error.
Here follows the code for the "func.php" file
function apply_leave($apply_date,$category,$type,$from,$to,$reason,$assign){
$result=mysql_query("INSERT INTO leave (apply_date, leave_category, leave_type, from_date, to_date, reason, duty_assign)
VALUES ('$apply_date', '$category', '$type', '$from', '$to', '$reason', '$assign')")or die("error on query".mysql_error());
Here follows the code for the "leave_apply.php" file
if(isset($_POST['apply'])){
$apply_date=$_POST['apply_date'];
$category=$_POST['category'];
$type=$_POST['type'];
$from=$_POST['from'];
$to=$_POST['to'];
$no_of_date=$_POST['no_of_date'];
$reason=$_POST['reason'];
$assign=$_POST['assign'];
$result=apply_leave($apply_date, $category, $type, $from, $to, $reason, $assign);
Upvotes: 2
Views: 1548
Reputation: 204766
leave
is a reserved keyword in MySQL and needs to be escaped by backticks.
INSERT INTO `leave` (...)
Upvotes: 4