title: Fatal error: Call to a member function prepare() on null (Register.PHP)
body: <p>so i'm not to big on website building. But I got a source off of one of my friends for a personal website and i'm trying to put everything together and in the (Register.Php) File I have an issue with it saying ("Fatal error: Call to a member function prepare() on null") my code for this is...</p>
  
  <pre><code>&lt;?php
  if (isset($_POST['registerBtn']))
  {
  
      if (empty($_POST['password']))
      {
      echo '&lt;div class="alert alert-error"&gt;&lt;center&gt;&lt;p&gt;&lt;font     color=\'black\'&gt;Please Choose A Password&lt;/font&gt;&lt;/p&gt;&lt;/center&gt;&lt;/div&gt;';
      }else
  
      $secure = isset($_POST['secure']) ? strtolower($_POST['Username']) : '';
      if ($secure == $_SESSION['username']) {
      unset($_SESSION['username']);
  
  
      $username = $_POST['username'];
      $password = $_POST['password'];
      $email = $_POST['email'];
      $checkUsername = $odb -&gt; prepare("SELECT COUNT(*) FROM `users` WHERE     `username` = :username");
      $checkUsername -&gt; execute(array(':username' =&gt; $username));
      $countUsername = $checkUsername -&gt; fetchColumn(0);
      $checkEmail = $odb -&gt; prepare("SELECT COUNT(*) FROM `users` WHERE     `email` = :email");
          $checkEmail -&gt; execute(array(':email' =&gt; $email));
          $countEmail = $checkEmail -&gt; fetchColumn(0);
          if ($countEmail &gt; 0)
          {
              echo '&lt;div class="alert alert-error"&gt;&lt;p&gt;&lt;font color=\'black\'&gt;    &lt;center&gt;Email Already In Use&lt;/center&gt;&lt;/font&gt;&lt;/p&gt;&lt;/div&gt;';
          }
          else
      {
      if (empty($username) || empty($password) || empty($email))
      {
              echo '&lt;div class="alert alert-error"&gt;&lt;center&gt;&lt;p&gt;&lt;font color=\'black\'&gt;Fill In All Fields&lt;/font&gt;&lt;/p&gt;&lt;/center&gt;&lt;/div&gt;';
      }
      else
      {
          if (!ctype_alnum($username) || strlen($username) &lt; 4 ||     strlen($username) &gt; 15)
          {
  echo '&lt;div class="alert alert-error"&gt;&lt;center&gt;&lt;p&gt;&lt;font color=\'black\'&gt;Fill     in all fields!&lt;/font&gt;&lt;/p&gt;&lt;/center&gt;&lt;/div&gt;';
  echo '&lt;div class="alert alert-error"&gt;&lt;center&gt;&lt;p&gt;&lt;font color=\'black\'&gt;Please     choose a username between 4-5 characters.&lt;/font&gt;&lt;/p&gt;&lt;/center&gt;&lt;/div&gt;';
          }
          else
          {
              if (!($countUsername == 0))
              {
  echo '&lt;div class="alert alert-error"&gt;&lt;center&gt;&lt;p&gt;&lt;font     color=\'black\'&gt;Username Taken.&lt;/font&gt;&lt;/p&gt;&lt;/center&gt;&lt;/div&gt;';
              }
              else
              {
                  if (!filter_var($email, FILTER_VALIDATE_EMAIL))
                  {
  echo '&lt;div class="alert alert-error"&gt;&lt;center&gt;&lt;p&gt;&lt;font     color=\'black\'&gt;Invalid email address.&lt;/font&gt;&lt;/p&gt;&lt;/center&gt;&lt;/div&gt;';
                  }
                  else
                  {
                          $insertUser = $odb -&gt; prepare("INSERT INTO `users`     VALUES(NULL, :username, :password, :email, 0, 0, 0, 0)");
                          $insertUser -&gt; execute(array(':username' =&gt;     $username, ':password' =&gt; SHA1($password), ':email' =&gt; $email));
  $ip = getRealIpAddr();
  $SQL = $odb -&gt; prepare('INSERT INTO `registerlogs` VALUES(:username, :ip,     UNIX_TIMESTAMP(), "")');
  $SQL -&gt; execute(array(':ip' =&gt; $ip, ':username' =&gt; $username));
  
      //change this to your email.
   $name3 = $odb -&gt; query("SELECT `sitename` FROM `SiteConfig` LIMIT 1") -&gt;     fetchColumn(0);
   $name2 = $odb -&gt; query("SELECT `header` FROM `forgotconfig` LIMIT 1") -&gt;     fetchColumn(0);
      $subject1 = $odb -&gt; query("SELECT `Subject` FROM `forgotconfig` LIMIT 1") -&gt; fetchColumn(0);
  $subject = "Welcome To $name2";
  $name1 = $odb -&gt; query("SELECT `email` FROM `forgotconfig` LIMIT 1") -&gt;     fetchColumn(0);
  
  
    $to   = "huzoorbux@gmail.com";
    $from = $odb -&gt; query("SELECT `email` FROM `forgotconfig` LIMIT 1") -&gt;     fetchColumn(0);
  
    $headers = "From: " . strip_tags($from) . "\r\n";
    $headers .= "Reply-To: ". strip_tags($from) . "\r\n";
    $headers .= "CC: $name1\r\n";
    $headers .= "MIME-Version: 1.0\r\n";
    $headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
  
  $message = '&lt;html&gt;&lt;body&gt;';
  
  $message .= '&lt;table width="100%"; rules="all" style="border:1px solid #3A5896;" cellpadding="10"&gt;';
  
  $message .= "&lt;tr&gt;&lt;td&gt;&lt;img src='/horizon.png' alt='Feive Stress' /&gt;&lt;/td&gt;&lt;/tr&gt;";
  
  $message .= "&lt;tr&gt;&lt;td colspan=2&gt;Thank you for signing up with us. Your new     account has been setup and you can now login to our client area using the      details below.
  Your details are as follows: 
  &lt;br&gt;
  &lt;br&gt;
  Username: $username
  &lt;br&gt;
  Email: $email
  &lt;br&gt;
  Password: ************* 
  &lt;br&gt;
  &lt;br&gt;
  To login, visit $name3
  &lt;br&gt;
  &lt;br&gt;
  Thank you for choosing $name2! 
  &lt;br&gt;
  &lt;br&gt;
  This is an automated response, please do not reply!&lt;/td&gt;&lt;/tr&gt;";
  
  
  $message .= "&lt;tr&gt;&lt;td colspan=2 font='colr:#999999;'&gt;&lt;I&gt;$name3&lt;br&gt;Registered     from IP: $ip&lt;/I&gt;&lt;/td&gt;&lt;/tr&gt;";
  
  $message .= "&lt;/table&gt;";
  
  $message .= "&lt;/body&gt;&lt;/html&gt;";
  
      // now lets send the email.
  mail($email, $subject, $message, $headers);
  
  
  echo '&lt;div class="alert alert-success"&gt;&lt;center&gt;&lt;p&gt;&lt;font     color=\'black\'&gt;Registered Successfully. Check Your Email Address.     Redirecting....&lt;/font&gt;&lt;/p&gt;&lt;/center&gt;&lt;/div&gt;&lt;meta http-equiv="refresh"     content="3;url=login.php"&gt;';
  }
  }
  }
  }
  }
  }
  }
  ?&gt;
  </code></pre>