您的SQL语法有错误; 查看与您的MySQL服务器版本对应的手册,以便在`leave l JOIN附近使用正确的语法

JJ_*_*___ -1 php mysql sql

我尝试编写一个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
Run Code Online (Sandbox Code Playgroud)

这是我的代码

<?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'];
Run Code Online (Sandbox Code Playgroud)

?>

<?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);
    ?>
Run Code Online (Sandbox Code Playgroud)

dno*_*eth 6

LEAVE是标准SQL中的关键字,在MySQL中可能是相同的.尝试使用反引号:

`LEAVE`
Run Code Online (Sandbox Code Playgroud)