您的SQL语法有错误;检查与MySQL服务器版本相对应的手册,找到在“leave l JOIN”附近使用的正确语法

时间:2021-09-12 00:58:57

I try to write a sql code to join three table together but it always show

我尝试编写一个sql代码将三个表连接在一起,但它总是显示出来

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 l JOIN employee e ON l.Emp_ID=e.Emp_ID JOIN department d ON e.Dept_ID= d.D' at line 1

Here is my code

这是我的代码

<?php

include("conn.php");

SESSION_START();

$aid = $_SESSION["eid"];
$check_user=mysql_query("select * from employee where Emp_ID='$aid'");
$row=mysql_fetch_assoc($check_user);

$leave   = mysql_query("select * from leave");
$_GET['Leave_ID'] = $leave['Leave_ID'];
$leaveID = $_GET['Leave_ID'];

?>

? >

<?php
        $sql  = mysql_query("select e.Emp_Fname, e.Emp_ID, e.Emp_Email, e.ContactNo_HP, e.ContactNo_Home, l.Date_Apply, l.Leave_Type, l.Leave_Start, l.Leave_End, l.Leave_Reason FROM leave l JOIN employee e ON l.Emp_ID=e.Emp_ID JOIN department d ON e.Dept_ID= d.Dept_ID where l.Leave_ID = $leaveID");


        if($sql == FALSE)
        {
            die(mysql_error());
        }
        $rows = mysql_fetch_assoc($sql);
    ?>

2 个解决方案

#1


6  

LEAVE is a keyword in Standard SQL, might be the same in MySQL. Try using backticks:

LEAVE是标准SQL中的关键字,在MySQL中可能也是一样的。试着用引号:

`LEAVE`

#2


0  

Leave is reserved MYSQL keyword (documentation) just escape your table name with ``

Leave是保留的MYSQL关键字(文档)只是用' '转义表名

#1


6  

LEAVE is a keyword in Standard SQL, might be the same in MySQL. Try using backticks:

LEAVE是标准SQL中的关键字,在MySQL中可能也是一样的。试着用引号:

`LEAVE`

#2


0  

Leave is reserved MYSQL keyword (documentation) just escape your table name with ``

Leave是保留的MYSQL关键字(文档)只是用' '转义表名