Jump to content

Syntax Error - LIMIT 1


Shanna

Recommended Posts

Hi,

 

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,

Shanna

 

Error Msg:

Database query failed. You have an error in your SQL syntax; check the maual that corresponds to your MySQL server version for the right syntax to use near 'LIMIT 1' at line 1.

 

SQL:

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);

confirm_query($result_set);

// REMEMBER:

// if no rows are returned, fetch_array will return false

if ($subject = mysql_fetch_array($result_set)) {

return $subject;

} else {

return NULL;

 

 

Link to comment
https://forums.phpfreaks.com/topic/260629-syntax-error-limit-1/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.