'MySQL Query using POST data always return wrong syntax

if (isset($_POST['id'])) {
    $row = $db->row("
        SELECT calendar_id, calendar_title, calendar_datetimestart, calendar_datetimeend, calendar_dow, calendar_color
        FROM (
            SELECT academic_schedule_id AS calendar_id, academic_schedule_name AS calendar_title, academic_schedule_datetimestart AS calendar_datetimestart, academic_schedule_datetimeend AS calendar_datetimeend, academic_schedule_dow AS calendar_dow, '#6453e9' AS calendar_color
            FROM academic_schedule_table
            WHERE academic_schedule_faculty = '".$_SESSION['siswa_faculty']."' AND academic_schedule_status = 'Active'
                                  
            UNION ALL
                                  
            SELECT appointment_table.dosen_schedule_id AS calendar_id, dosen_schedule_table.dosen_schedule_name AS calendar_title, dosen_schedule_table.dosen_schedule_datetimestart AS calendar_datetimestart, dosen_schedule_table.dosen_schedule_datetimeend AS calendar_datetimeend, Null AS calendar_dow, '#28464b' AS calendar_color
            FROM appointment_table  
            INNER JOIN dosen_table ON dosen_table.dosen_id = appointment_table.dosen_id 
            INNER JOIN dosen_schedule_table ON dosen_schedule_table.dosen_schedule_id = appointment_table.dosen_schedule_id 
            WHERE appointment_table.siswa_id = ".$_SESSION['siswa_id']." AND appointment_table.status = 'Disetujui'
        ) WHERE calendar_id = ".$_POST['id']."");

I'm trying to POST 'id' and the data is showing up but it always give me syntax error

Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'WHERE calendar_id = 13

Where i did it wrong?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source