"limit" error

hello please i am having this error, and it states line 1
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
the mark up language is below


<?php
//this file is the place to save all the basic functions
function confirm_query($result_set) {
if (!$result_set) {
         die("Database query failed: " . mysql_error());
         }
         }
       function get_all_subjects() {
         global $connection;
         	//3. perform database querry
	$query = "SELECT * FROM subjects ORDER BY position ASC"; 
		$subject_set = mysql_query($query, $connection);
   confirm_query($subject_set);
   return $subject_set;
  }
  function get_pages_for_subject($subject_id) {
  global $connection;
 $query = "SELECT * 
        FROM pages WHERE subject_id = {$subject_id} ORDER BY position ASC";
    $page_set = mysql_query($query, $connection);
    confirm_query($page_set);
    return $page_set;
    }
    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);
  if  ($subject = mysql_fetch_array($result_set)) {
   return $subject;
   }else{
   return NULL;
   }
   }
?>

LIMIT 1 is fine. my guess is that $subject_id is empty.

i am following a training material, $subject_id is an argument of the function defined, and it was substituted in the content page mark up below.


<?php require_once("include/connection.php"); ?>
<?php require_once("include/functions.php"); ?>
<?php
if (isset($_GET['subj'])) {
     $sel_subj = $_GET['subj'];
     $sel_page = "";
     } elseif (isset($_GET['page'])) {
     $sel_subj = "";
     $sel_page = $_GET['page'];
     } else {
     $sel_subj = "";
     $sel_page = "";
     }
     $sel_subject = get_subject_by_id($sel_subj);
?>
<?php include("include/header.php"); ?>
<div id="navigation">
<ul>
       <?php
	//3. perform database querry
      $subject_set = get_all_subjects();
        //4 use returned data
    while($subject = mysql_fetch_array($subject_set)) {
        echo "<li><a href=\\"contents.php?subj=" . urlencode($subject["id"]) . 
        "\\">{$subject["menu_name"]}</a></li>";
  $page_set = get_pages_for_subject($subject["id"]);
        //4 use returned data
       echo "<ul class=\\"pages\\">";
    while($page = mysql_fetch_array($page_set)) {
        echo "<li><a href=\\"contents.php?page=" . urlencode($page["id"]) . 
        "\\">{$page["menu_name"]}</a></li>";
        }
        echo"</ul>";
        
        }
		?>
	</ul>
</div> <!--end of navigation div -->
<div id="bodycontent">
 <h2> <?php echo $sel_subject['menu_name']; ?></h2>
 <p>
<br />
 <?php echo $sel_page; ?><br />
 </p>
</div>
</div>
<?php require("include/footer.php"); ?>

yeah, i’m guessing that $sel_sub doesn’t have a value by the time it hits

$sel_subject = get_subject_by_id($sel_subj);

did you miss something in the materials? i would assume that you wouldn’t want to run the function if $sel_sub is empty as it wouldn’t return anything (or generate an error in your instance) since it has to have an ID to get the subject.