title: Fatal error: Call to a member function query() on a non object
body: <p>I've got this error:</p>
  
  <p>Fatal error: Call to a member function query() on a non-object in /Applications/XAMPP/xamppfiles/htdocs/login.php on line 8</p>
  
  <p>The line is this:</p>
  
  <pre><code>$res = $mysqli-&gt;query("SELECT * FROM user WHERE user='$user' and password='$pw'");
  </code></pre>
  
  <p>This is login.php:</p>
  
  <pre><code>$user = $_POST['user'];
  $pass = $_POST['pass'];
  $pw = md5($pass); 
  include_once('connect.php');
  
  function check_login($user,$pw,&amp;$result){
      $res = $mysqli-&gt;query("SELECT * FROM user WHERE user='$user' and password='$pw'");
      $cont = 0;
      while($row = $res-&gt;fetch_object()){
          $cont++;
          $result = $row;
      }
      if($cont == 1){
          return 1;
      }
      else{
          return 0;
      }
  }
  
  if(!isset($_SESSION['userid'])){
    if(isset($_POST['login'])){
      if(check_login($user,$pw,$result) == 1){
          session_start();
          $_SESSION['userid'] = $result-&gt;id_user;
          header("location:index.php?var=ok");
      }
      else{
          header('location:index.php?var=log');
      }
    }
  }
  </code></pre>
  
  <p>And the code of connect.php :</p>
  
  <pre><code>$mysqli = new mysqli('localhost', 'root', 'pass', 'cms' );
  if ($mysqli-&gt;connect_error) {
     die('Error de Conexión (' . $mysqli-&gt;connect_errno . ') '
          . $mysqli-&gt;connect_error);
   }
  </code></pre>
  
  <p>What could be the problem? Problems connecting the database?</p>