MySQL Forums
Forum List  »  PHP

Syntax Error - Syntax for 'LIMIT 1'
Posted by: Doug Johnson
Date: April 09, 2012 10:18AM


I am running MAMP on my Mac with PHP 5.2.17 and MySQL 5.5.22 dB. I am using the PHP with MySQL Essential Training course to learn PHP and My SQl. Part of one of the steps in Ch. 12 has you execute the query below but when I do I get the following error msg. I have looked and tried various things but cannot get his query to work. Please help !!!

Thanks in advance,

Error Msg:
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.

function get_subject_by_id($subject_id) {
global $connection;
$query = "SELECT * ";
$query .= "FROM subjects ";
$query .= "WHERE id=" . $subject_id ." ";
$query .= "LIMIT 1";
$result_set = mysql_query($query, $connection);
// if no rows are returned, fetch_array will return false
if ($subject = mysql_fetch_array($result_set)) {
return $subject;
} else {
return NULL;

Edited 2 time(s). Last edit at 04/09/2012 10:19AM by Doug Johnson.

Options: ReplyQuote

Written By
Syntax Error - Syntax for 'LIMIT 1'
April 09, 2012 10:18AM

Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.