I need help with this error, please!

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
ristick
Forum Newbie
Posts: 1
Joined: Sun Jan 25, 2009 6:00 pm

I need help with this error, please!

Post by ristick »

I've been designing a site for about 2 days now.
Everything was working fine until I put this NECESSARY code in
function get_subject_by_id($subject_id) {
global $connect;
$query = "SELECT * ";
$query .= "FROM subjects ";
$query .= "WHERE id=" . $subject_id ." ";
$query .= "LIMIT 1";
$result_set = mysql_query($query, $connect);
confirm_query($result_set);
if ($subject = mysql_fetch_array($result_set)) {
return $subject;
} else {
return NULL;
}
}
and it returned this error (I'm running on localhost)
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
User avatar
Eran
DevNet Master
Posts: 3549
Joined: Fri Jan 18, 2008 12:36 am
Location: Israel, ME

Re: I need help with this error, please!

Post by Eran »

Check that $subject_id has any value
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: I need help with this error, please!

Post by Benjamin »

Also, place backticks around id as it's a reserved MySQL keyword.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: I need help with this error, please!

Post by John Cartwright »

It is helpful to

Code: Select all

echo $query;
 
to make sure the query is as you would expect.
Post Reply