title: PHP Stuck on Mysqli_error()
body: <p>I am new to php still learning i have made a navigation with the drop down submenus its working when im inserting new item in navigation but the problem exist when i try to edit the same navigation i get the error in function everything seems fine need help.</p>
  
  <p>![Edit Form][1]</p>
  
  <p>Error:</p>
  
  <pre><code>&lt;code&gt;
  Database Query Failed in get subject by idYou 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
  &lt;/code&gt;
  </code></pre>
  
  <p>functions.php</p>
  
  <pre><code>&lt;code&gt;
  
      // Get Subject By ID
      function get_subject_by_id($subject_id){
      global $connection;
      $query = "SELECT * FROM subjects WHERE id = {$subject_id} LIMIT 1";
  
      $result_set = mysqli_query($connection, $query);
      if(!$result_set){
          die("Database Query Failed in get subject by id" . mysqli_error($connection));
      }
      if($subject_data = mysqli_fetch_array($result_set)) {
          return $subject_data;
      } else {
          return null;
      }
      }
  &lt;/code&gt;
  </code></pre>
  
  <p>edit_subject.php</p>
  
  <pre><code>&lt;code&gt;
  &lt;?php include('includes/connection.php'); ?&gt;
  &lt;?php require_once('includes/functions.php'); ?&gt;
  
  &lt;?php 
      if(isset($_POST['submit'])) {
      $id = $_GET['subj'];
      $menu_name = $_POST['menu_name'];
      $position = $_POST['position'];
      $visible = $_POST['visible'];
      $content = $_POST['content'];
  
      $query = "UPDATE subjects SET menu_name = '{$menu_name}', position = {$position}, visible = {$visible}, content = '{$content}' WHERE id = {$id}";
  
      $result_update = mysqli_query($connection, $query);
  
      if(mysqli_affected_rows($connection) == 1){
          $message = "The Subject was successfully created.";
      } else {
  
      }
  
      }
  ?&gt;
  
  
  &lt;?php
      if(isset($_GET['subj'])){
          $sel_subject = get_subject_by_id($_GET['subj']);
          $sel_page = NULL;
      } elseif (isset($_GET['page'])) {
          $sel_subject = NULL;
          $sel_page = get_page_by_id($_GET['page']);
      } else {
          $sel_subject = NULL;
          $sel_page = NULL;
      }
  
  ?&gt;
  
  
  &lt;?php include('includes/header.php'); ?&gt;
                  &lt;div class="sidebar"&gt;
                      &lt;ul class="sideNav"&gt;
                      &lt;?php 
                          $query_sub = "SELECT * FROM subjects";
                          $subject_set = mysqli_query($connection, $query_sub);
                          if(!$subject_set){
                              die("Database Query Failed1");
                          }
  
                          while($subject = mysqli_fetch_array($subject_set)){
                          ?&gt;
                              &lt;li&gt;&lt;a href="edit_subject.php?subj=&lt;?php echo $subject["id"]; ?&gt;"&gt;&lt;?php echo $subject["menu_name"]; ?&gt;&lt;/a&gt;
                              &lt;?php
                              $query_page = "SELECT * FROM pages WHERE subject_id = {$subject["id"]}";
                              $page_set = mysqli_query($connection, $query_page);
                              if(!$page_set){
                                  die("Database Query Failed2");
                              } ?&gt;
                              &lt;ul&gt;                            
                              &lt;?php
                              while($page = mysqli_fetch_array($page_set))
                              {
                                  ?&gt;&lt;li&gt;&lt;a href="content.php?page=&lt;?php echo $page["id"]; ?&gt;"&gt;&lt;?php echo $page["menu_name"]; ?&gt;&lt;/a&gt;&lt;/li&gt;&lt;?php
                              } ?&gt;
                          &lt;/ul&gt;
                          &lt;/li&gt;
                          &lt;?php } ?&gt;
                      &lt;/ul&gt;
                      &lt;br&gt;
                      &lt;a href="new_subject.php"&gt;+ Add a new Subject&lt;/a&gt;
                  &lt;/div&gt;&lt;!-- end of sidebar --&gt;
  
                  &lt;h2&gt;&lt;a href="index.php"&gt;Edit Subject: &lt;?php echo $sel_subject['menu_name']; ?&gt;&lt;/a&gt;&lt;/h2&gt;
  
                  &lt;div class="main"&gt;
                  &lt;br/&gt; &lt;br/&gt;
                  &lt;?php if(!empty($message)) { ?&gt; &lt;p&gt;&lt;?php echo $message; ?&gt;&lt;/p&gt; &lt;?php } ?&gt;
                  &lt;form action="edit_subject.php?subj=&lt;?php $sel_subject['id']; ?&gt;" method="post"&gt;
                      &lt;fieldset&gt;
                          &lt;legend&gt;Edit Subject:&lt;/legend&gt;
                          &lt;p&gt;Subject Name:
                              &lt;input type="text" name="menu_name" value="&lt;?php echo $sel_subject['menu_name']; ?&gt;"&gt;
                          &lt;/p&gt;
                          &lt;p&gt;Position:
                              &lt;select name="position"&gt;
                              &lt;?php
                              $query_opt = "SELECT * FROM subjects ORDER BY position ASC";
                              $subject_opt = mysqli_query($connection, $query_opt);
                              if(!$subject_opt){
                              die("Database Query Failed3");
                              }
                              $subject_count = mysqli_num_rows($subject_opt);
                              for($count=1; $count &lt;= $subject_count+1; $count++){
                                  echo "&lt;option value=\"{$count}\"";
                                  if($sel_subject['position'] == $count){
                                      echo " selected";
                                      }
                                  echo "&gt;{$count}&lt;/option&gt;";
                              } 
                              ?&gt;  
                              &lt;/select&gt;
                          &lt;/p&gt;
                          &lt;p&gt;Visible:
                              &lt;input type="radio" name="visible" value="0"&lt;?php if($sel_subject['visible'] == 0){ echo " checked"; } ?&gt;&gt; No
                              &amp;nbsp;
                              &lt;input type="radio" name="visible" value="1"&lt;?php if($sel_subject['visible'] == 1){ echo " checked"; } ?&gt;&gt; Yes
                          &lt;/p&gt;
                          &lt;p&gt;Content:&lt;br/&gt;
                              &lt;textarea name="content" rows="20" cols="150"&gt;&lt;?php echo $sel_subject['content']; ?&gt;&lt;/textarea&gt;
                          &lt;/p&gt;
                          &lt;p&gt;
                              &lt;input type="submit" name="submit" value="Add Subject" class="button-submit"&gt;
                          &lt;/p&gt;
                      &lt;/fieldset&gt;
                  &lt;/form&gt;
                      &lt;br /&gt;&lt;br /&gt;
                  &lt;/div&gt;&lt;!-- end of main --&gt;
  &lt;?php include('includes/footer.php'); ?&gt;
  &lt;/code&gt;
  </code></pre>