title: Fatal error: Call to a member function query() on a non-object in .php file
body: <p>I'm new to PHP and SQL, but I'm trying to create a login script for my webapp.
  For some reason I'm stuck. When the username or password-field is empty, there is an alert, but when they are both filled in correct or incorrect, there is no alert.</p>
  
  <p>When I open the website in my browser (Chrome) and inspect the page, I get:</p>
  
  <p><strong>"POST ../App/auth.php 500 (Internal Server Error)"</strong> </p>
  
  <p>When I open the error.log-file from my server, I get:</p>
  
  <p><strong>"PHP Fatal error:  Call to a member function query() on a non-object in ../App/class.manageUsers.php on line 24, referer: ../App/login.php"</strong></p>
  
  <p>line 24 in class.manageUsers.php is:</p>
  
  <pre><code>$query = $this-&gt;link-&gt;query("SELECT * FROM users WHERE username = '$username' AND
  password = '$password' LIMIT 1");
  </code></pre>
  
  <p>class.manageUsers.php:</p>
  
  <pre><code>&lt;?php
  
  include_once('class.database.php');
  
  class ManageUsers{
  
      protected $link;
  
      function __construct(){
          $db_conn = new ManageDatabase;
          $this-&gt;link = $db_conn-&gt;connect();
          return $this-&gt;link;
      }
      function addUsers($username,$firstname,$lastname,$email,$password,$user_level){
          $query = $this-&gt;link-&gt;prepare("INSERT INTO users (username,firstname,lastname,email,password,user_level)
              VALUES (?,?,?,?,?,?)
          ");
          $values = array($username,$firstname,$lastname,$email,$password,$user_level);
          $query-&gt;execute($values);
          $rowCount = $query-&gt;rowCount();
          return $rowCount;
      }
      function loginUsers($username,$password){
          $query = $this-&gt;link-&gt;query("SELECT * FROM users WHERE username = '$username' AND password = '$password' LIMIT 1");
          $rowCount = $query-&gt;rowCount();
          return $rowCount;           
      }
      function listUsers($user_id = null){
          if(isset($user_id))
          {
          $query = $this-&gt;link-&gt;query("SELECT * FROM users WHERE id = '$user_id' LIMIT 1");
          }
          else
          {
          $query = $this-&gt;link-&gt;query("SELECT * FROM users ORDER BY id DESC");
          }
          $rowCount = $query-&gt;rowCount();
          if($rowCount &gt;= 1)
          {
              $result = $query-&gt;fetchAll();
          }
          else
          {
              $result = 0;
          }
          return $result;
      }
  
      function editUsers($user_id,$param){
          foreach ($param as $key =&gt; $value)
          {
          $query = $this-&gt;link-&gt;query("UPDATE users SET $key = '$value' WHERE id = '$user_id' LIMIT 1");
          }
          $rowCount = $query-&gt;rowCount();
          return $rowCount;
      }
  
      function deleteUsers($user_id){
          $query = $this-&gt;link-&gt;query("DELETE FROM users WHERE id = '$user_id' LIMIT 1");
          $rowCount = $query-&gt;rowCount();
          return $rowCount;
      }
  
  }
  
  ?&gt;
  </code></pre>
  
  <p>class.database.php:</p>
  
  <pre><code>&lt;?php
  
  class ManageDatabase{
  
      protected $db_conn;
      protected $db_host = 'localhost';
      protected $db_name = 'jqueryMobile';
      protected $db_user = 'root';
      protected $db_pass = '';
  
      function connect(){
          try{
              $this-&gt;db_conn = new PDO("mySQL:host=$this-&gt;db_host;dbname=$this-&gt;db_name",$this-&gt;db_user,$this-&gt;db_pass);
              return $this-&gt;db_conn;
          }
          catch(PDOexception $e){
              return $e-&gt;getMessage();
          }
      }
  
  }
  ?&gt;
  </code></pre>
  
  <p>I hope someone can find where it seems to go wrong. 
  Thanks.</p>