title: Fatal error Call to a member function prepare() on null
body: <p>I am trying to check if email was already used in Registration. It worked well when I was working on it in the school but now it suddenly shows an error: </p>
  
  <blockquote>
    <p>Fatal error: Call to a member function prepare() on null</p>
  </blockquote>
  
  <p>I use this to include </p>
  
  <pre><code>define("dbserver", "localhost");
  define("dbuser", "user");
  define("dbpass", "");
  define("dbname", "user");    
  
  
  $db = new PDO(
  "mysql:host=" .dbserver. ";dbname=" .dbname,dbuser,
  array(
  PDO::MYSQL_ATTR_INIT_COMMAND =&gt; "SET NAMES utf8",
  PDO::MYSQL_ATTR_INIT_COMMAND =&gt; "SET CHARACTER SET utf8"
  ) );
  </code></pre>
  
  <p>In here</p>
  
  <pre><code>session_start();
  include "DBjoin.php";
  if(isset($_POST["email"])) {
    $_SESSION['email'] = $_POST["email"];
    }   
  if(isset($_POST["nick"])) {
    $_SESSION['nick'] = $_POST["nick"];         
  }    
  if(isset($_POST["pass"])) {
    $_SESSION['pass'] = $_POST["pass"];
    $_SESSION['pass'] = base64_encode($_SESSION['pass']);    
  }
  $sthandler = $db-&gt;prepare("SELECT Email FROM Registrace WHERE Email =     :email");
  $sthandler-&gt;bindParam(':email', $_SESSION['email']);
  $sthandler-&gt;execute();               
  if(filter_var($_SESSION['email'], FILTER_VALIDATE_EMAIL)) {
  if($sthandler-&gt;rowCount() &gt; 0){
        echo "Email is used";}
  </code></pre>