I’m getting an error that says “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”
I’m doing this through the Lynda.com PHP/MySql tutorial. I’ve compared the code several times, checked the FAQ’s, and tried changing various troubleshooting, but I can’t figure it out.
The code is:
function getSubjectById($subject_id) {
global $connection;
$query = "SELECT * ";
$query .= "FROM subjects ";
$query .= "WHERE id=" . $subject_id ." ";
$query .= " LIMIT 1";
$resultSet = mysql_query($query, $connection);
confirmQuery($resultSet);
// if no rows are returned, then it comes back as false.
if ($subject = mysql_fetch_array($resultSet)) {
return $subject;
} else {
return NULL;
}
}
function getPagesById($page_id) {
global $connection;
$query = "SELECT * ";
$query .= "FROM pages ";
$query .= "WHERE id=" . $page_id ." ";
$query .= " LIMIT 1";
$resultSet = mysql_query($query, $connection);
confirmQuery($resultSet);
// if no rows are returned, then it comes back as false.
if ($page = mysql_fetch_array($resultSet)) {
return $page;
}else {
return NULL;
}
}