title: Fatal errir : Uncaught Error: Call to a member function close() on
body: <p>The error:</p>
  
  <blockquote>
    <p>Fatal error: Uncaught Error: Call to a member function close() on
    boolean in C:\xampp\htdocs\Project\script\register.php:69 </p>
    
    <p>Stack trace: #0 C:\xampp\htdocs\Project\index.php(2): include_once() #1 {main} thrown in C:\xampp\htdocs\Project\script\register.php on line 69</p>
  </blockquote>
  
  <p>The error occurred when i passed proper data that gets through the validation.</p>
  
  <p>The file :</p>
  
  <pre><code>&lt;?php 
  include_once 'functions.php';
  include_once 'dbconnect.php';
  // Returns the request method used to access the page
  if ($_SERVER["REQUEST_METHOD"] == "POST"){
      $err="";
  
  
  // Validation .... 
   .....
  // End of it
  
   $prep_stmt = "SELECT id FROM members WHERE email = ? LIMIT 1";
  $stmt = $sql_db-&gt;prepare($prep_stmt);
  
  // check existing email  
  if ($stmt) {
      $stmt-&gt;bind_param('s', $email);
      $stmt-&gt;execute();
      $stmt-&gt;store_result();
  
      if ($stmt-&gt;num_rows == 1) {
          // A user with this email address already exists
          $err .= '&lt;p class="error"&gt;A user with this email address already exists.&lt;/p&gt;';
                      $stmt-&gt;close();
      }
  } else {
      $err .= '&lt;p class="error"&gt;Database error Line 39&lt;/p&gt;';
              $stmt-&gt;close();
  }
  
  // check existing username
  $prep_stmt = "SELECT id FROM members WHERE username = ? LIMIT 1";
  $stmt = $sql_db-&gt;prepare($prep_stmt);
  
  if ($stmt) {
      $stmt-&gt;bind_param('s', $username);
      $stmt-&gt;execute();
      $stmt-&gt;store_result();
  
              if ($stmt-&gt;num_rows == 1) {
                      // A user with this username already exists
                      $err .= '&lt;p class="error"&gt;A user with this username already exists&lt;/p&gt;';
                      $stmt-&gt;close();
              }
      } else {
              $err .= '&lt;p class="error"&gt;Database error line 55&lt;/p&gt;';
              $stmt-&gt;close();
      }
  
  // Hashing, salting and inserting the values.
     ....
  // End of file.
  </code></pre>
  
  <p><p>Searched for some answer why is there a problem and nothing found. <p>
  <a href="https://stackoverflow.com/questions/9722159/fatal-error-call-to-a-member-function-close-on-a-non-object-mysqli-issue">Another thread like this</a> - The $stmt->close() is in an if function. </p>