title: php and mysql_num_rows not detecting if something isnt in the database
body: <p>I have a form on a website that needs validating before entering the form data into the database. </p>
  
  <p>Its checking whether a username already exists by user the mysql_num_rows function. But i cannot seem to get it working. When testing, it doesn't let a new username be added. </p>
  
  <p>Here is the full code being used: </p>
  
  <pre><code>&lt;?php
  session_start();
  
  include("databaseConnect.php");
  // Insert a row of information into the table "example"
  
  
  // check if username is already in database
  if(mysql_num_rows(mysql_query("SELECT userName FROM registeredUsers WHERE userName =     '$_POST[userName]'"))){
   echo "Username: ". $_POST[userName]." already exists in the Database&lt;br&gt;&lt;br&gt;";
      echo "You will be redirect back to the form in 5 seconds";
  $ref = $_SERVER['HTTP_REFERER'];
  header( 'refresh: 5; url='.$ref);
  
  //check if hemis is already in database
  }elseif(mysql_num_rows(mysql_query("SELECT hemis FROM registeredUsers WHERE hemis = '$_POST[hemis]'"))){
  echo "Student [Hemis] Number: ". $_POST[hemis]." already exists in the Database&lt;br&gt;&lt;br&gt;";
  echo "You will be redirect back to the form in 5 seconds";
  $ref = $_SERVER['HTTP_REFERER'];
  header( 'refresh: 5; url='.$ref);
  
  
  // if all the conditions above are fine, it will insert the data to MySQL
  }else{
    mysql_query("INSERT INTO registeredUsers
  (firstName, lastName, hemis, userName, MAC) VALUES('$_POST[firstName]', '$_POST[lastName]', '$_POST[hemis]', '$_POST[userName]', '$_POST[mac]' ) ")
  or die(mysql_error());
  
  echo "Data Inserted! &lt;br&gt;&lt;br&gt;";
  }
  </code></pre>
  
  <p>Thanks a lot :)</p>