yuanven Posted September 15, 2022 Share Posted September 15, 2022 (edited) Hello! I am using PHP version 5.7 and Code Igniter 3 I have 2 tables. 1. krs 2. matakuliah this is the code $nim = $this->input->post('nim', TRUE); $thn_ak = $this->input->post('$id_thn_ak', TRUE); $query = "SELECT krs.id_thn_ak ,krs.kode_matakuliah ,matakuliah.nama_matakuliah ,matakuliah.sks ,krs.nilai FROM krs INNER JOIN matakuliah ON (krs.kode_matakuliah = matakuliah.kode_matakuliah) WHERE krs.nim = $nim AND krs.id_thn_ak = $thn_ak"; and I got an error like this A Database Error Occurred Error Number: 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 'INNER JOIN matakuliah ON (krs.kode_matakuliah = matakuliah.kode_matak...' at line 9 SELECT krs.id_thn_ak ,krs.kode_matakuliah ,matakuliah.nama_matakuliah ,matakuliah.sks ,krs.nilai FROM krs WHERE krs.nim = 18024114 AND krs.id_thn_ak = INNER JOIN matakuliah ON (krs.kode_matakuliah = matakuliah.kode_matakuliah) Filename: C:/xampp/htdocs/sisfo_akademik/system/database/DB_driver.php Line Number: 692 Thank You. Edited September 15, 2022 by yuanven Quote Link to comment https://forums.phpfreaks.com/topic/315326-sql-syntax-error-using-select-from-inner-join-on-where/ Share on other sites More sharing options...
Solution requinix Posted September 15, 2022 Solution Share Posted September 15, 2022 48 minutes ago, yuanven said: this is the code No it is not. Look at the query in your code: $query = "SELECT krs.id_thn_ak ,krs.kode_matakuliah ,matakuliah.nama_matakuliah ,matakuliah.sks ,krs.nilai FROM krs INNER JOIN matakuliah ON (krs.kode_matakuliah = matakuliah.kode_matakuliah) WHERE krs.nim = $nim AND krs.id_thn_ak = $thn_ak"; Look at the query in the error message: SELECT krs.id_thn_ak ,krs.kode_matakuliah ,matakuliah.nama_matakuliah ,matakuliah.sks ,krs.nilai FROM krs WHERE krs.nim = 18024114 AND krs.id_thn_ak = INNER JOIN matakuliah ON (krs.kode_matakuliah = matakuliah.kode_matakuliah) They are not the same query. Now look at this part of the query that was shown in the error message: ...FROM krs WHERE krs.nim = 18024114 AND krs.id_thn_ak = INNER JOIN matakuliah... See why the query does not work? Now look at this part of your code: $this->input->post('$id_thn_ak', TRUE); Look carefully. Are you sure that is correct? 1 Quote Link to comment https://forums.phpfreaks.com/topic/315326-sql-syntax-error-using-select-from-inner-join-on-where/#findComment-1600565 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.