<?php
$query = "SELECT * ";
$query .= "FROM subjects ";
$query .= "WHERE id='" . $subject_id ."' ";
$query .= "LIMIT 1";
?>
The problem cause is in this line: The error : "Database query failed: 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 'LIMIT 1' at line 1"
So why... despite the syntax is right. Given me that error ?!
You don't need to concatenate the variable you can use
<?php
$query = "SELECT * ";
$query .= "FROM subjects ";
$query .= "WHERE id='$subject_id' ";
$query .= "LIMIT 1";
?>
You have two semi-colons after your variable as well, and if your variable is a integer, it doesnt need to be in single quotes either.
The error message is from the execution of a line of code not shown in your question.
One obvious possibility is that the string value produced by this code is not being passed to MySQL. Another possibility is that $subject_id
contains a string value that is being interpreted as SQL text, and the $query
does not contain what you think it contains. There's a lot of other possibilities.
For debugging issues like this, we really need to identify the line of code that is actually throwing the error. (In your case, it's going to be a call to a mysql_, mysqli or PDO execute or prepare function or method.)
What you can do is add an echo
or var_dump
of the ACTUAL SQL text that is being passed to MySQL, on a line immediately preceding the line that is throwing the error.
For example, you would get this error message if a line of code after this code, and before the parse or execute call, modifies $query
$query .= " LIMIT 1";
That would add a second LIMIT clause on the query, which is invalid, and would throw the same error you are getting.
To reiterate: the lines of code posted in your question are NOT throwing an error. The lines of code you posted are simply assigning a string value to a variable. (This may be the string value that is being passed to MySQL, but we don't see that anywhere in your code.)
You are using 'subject_id'
may be int format have some problem so use subject_id
and Limit 1
alternate Limit 0,1
.
<?php
$query = "SELECT * ";
$query .= "FROM subjects ";
$query .= "WHERE id=" . $subject_id;
$query .= "LIMIT 0,1";
?>