title: How to check if a user(already registered with log in form) exists in the database?
body: <p>I've been trying to create a login page where users who sign up are written in a database. I want to check, when a user tries to log in, the code should find if the user is registered before(if exists in the table in the database). And if exists he should sign in and to be redirected to another page(in this case kontakt.php). Here's what I've done till now, but it shows me error:
  Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\BookShop\login.php on line 14
  Is something wrong with the query?</p>
  
  <pre><code>&lt;?php
  session_start();
  require "C:/xampp/htdocs/BookShop/DButils.php";
  
  //opening a DB connection
  $connection = @ mysql_connect($hostname, $username, $password);
  
  //selecting DB
  mysql_select_db($dbname, $connection);
  
  $username=mysql_real_escape_string($_POST['username']);
  $password=mysql_real_escape_string($_POST['password']);
  
  $query = mysql_num_rows(mysql_query("SELECT * FROM kupuvac WHERE username = '$username'             AND password = '$password'"));
  
  if($query == 1)
   {              
  
     header("Location:kontakt.php");
  
    }
  else if ($query == 0 )
     {
  
      echo "Please try again";
     }
   ?&gt;
  </code></pre>