title: Check the username in the database, avoid duplicates
body: <p>I want to do a query to my database if there are existing users of the same name. then I want to send a "return false". but I get only one felmeddalnde right now. </p>
  
  <blockquote>
    <p>Warning: mysql_num_rows () Expects Parameter 1 to be resource, boolean</p>
  </blockquote>
  
  <pre><code>function DoInsertNewUser($name, $password) {
      var_dump($name);
      var_dump("inne i databasen");
      //tar kontakt med databasen
      $DBConnection = new DBConnection();
      $DBConnection -&gt; Connect();
  
      $result = mysql_query("SELECT m_username FROM user WHERE m_username ='$name'");
      $number_of_rows = mysql_num_rows($result);
  
      var_dump($number_of_rows);
  
      if ($number_of_rows  &gt; 1) {
          var_dump('Användarnamnet finns redan');
      }
      else 
      {
          //ställer en sql-fråga.
          $sql = "INSERT INTO `user`(`m_username`,`m_password`) VALUES (?,?)";
  
          $stmt = $DBConnection -&gt; prepare($sql);
          $stmt -&gt; bind_param("ss", $name, $password);
          if ($stmt === FALSE) {
  
              return false;
          }
  
          $stmt -&gt; execute();
          // ger resultet.
          while ($stmt -&gt; fetch()) {
              $stmt -&gt; close();
              return true;
          }
          $stmt -&gt; close();
          return false;
      }
  }
  </code></pre>