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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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