Jump to content

SQL syntax error (using SELECT FROM INNER JOIN ON WHERE)


yuanven
 Share

Go to solution Solved by requinix,

Recommended Posts

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.

1 table.png

2 table.png

code.png

error.png

Edited by yuanven
Link to comment
Share on other sites

  • Solution
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?

  • Like 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.