title: Registering new users with different usernames and emails
body: <p>I'm having a problem in my registration page. You can register a new user with a username already registered by using a different email.</p>
  
  <p>For example, first registration:</p>
  
  <p><strong>Username: User-1</strong><br>
  Password: 123<br>
  <strong>Email: 123@email.com</strong></p>
  
  <p>Message received: <strong>"You are Registered"</strong>      </p>
  
  <p>Another registration:</p>
  
  <p><strong>Username: User-1</strong><br>
  Password: 123<br>
  <strong>Email: another_email@email.com</strong></p>
  
  <p>Message received: <strong>"You are Registered"</strong></p>
  
  <p>The page should be displaying <strong>"Username already exists"</strong> but that is not happenning. I really don't know what is missing.</p>
  
  <p>Here is the code:</p>
  
  <pre><code>&lt;?php
  
  if(isset($_POST["register"])){
  
  $username = $_POST['username'];
  $password = $_POST['password'];
  $email = $_POST['email'];
  
  if (!empty($username) &amp;&amp; !empty($password) &amp;&amp; !empty($email)){
      $checkusername = mysql_query("SELECT `id` FROM `user` WHERE `username` = '".$username."'") or die(mysql_error());
      $checkemail = mysql_query("SELECT `id` FROM `user` WHERE `email` = '".$email."'") or die(mysql_error());
  
      if(mysql_num_rows($checkusername) == 1){
          ?&gt;&lt;p&gt;&lt;?php echo "Username already exists"; ?&gt;&lt;/p&gt;&lt;?php
      }
      if(mysql_num_rows($checkemail) == 1){
          ?&gt;&lt;p&gt;&lt;?php echo "Email already exists"; ?&gt;&lt;/p&gt;&lt;?php
      }
      else{
          mysql_query("INSERT INTO `database`.`user`(`username`,`password`,`email`) VALUES ('".$username."','".$password."','".$email."')") or die(mysql_error());
          ?&gt;&lt;p&gt;&lt;?php echo "You are Registered"; ?&gt;&lt;/p&gt;&lt;?php
      }
  }
  else{
  
      if(empty($username)){
          $error[] = "Please insert a username";
      }
      if(empty($password)){
          $error[] = "Please insert a password";
      }
      if(empty($email)){
          $error[] = "Please insert a email";
      }
      foreach ($error as $value) {
          ?&gt;&lt;p&gt;&lt;?php echo "'".$value."'&lt;br&gt;"; ?&gt;&lt;/p&gt;&lt;?php
      }
  }
  }
  ?&gt;
  </code></pre>
  
  <p><strong>EDIT:</strong></p>
  
  <p>Thanks for the help guys but i found a better solution for the problem. I'm using <strong>$value</strong> also to display <strong>"Username already exists"</strong> and <strong>"Email already exists"</strong> and also changed <strong>mysql_num_rows($checkusername) == 1</strong> to <strong>mysql_num_rows($checkusername) > 0</strong> as some of you suggested. Here is the new code:</p>
  
  <pre><code>&lt;?php
  include "header.php";
  
  if(isset($_POST["register"])){
  
  $username = $_POST['username'];
  $password = $_POST['password'];
  $email = $_POST['email'];
  
  if (!empty($username) &amp;&amp; !empty($password) &amp;&amp; !empty($email)){
  
      $checkusername = mysql_query("SELECT `id` FROM `user` WHERE `username` = '".$username."'");
      $checkemail = mysql_query("SELECT `id` FROM `user` WHERE `email` = '".$email."'");
  
      if(mysql_num_rows($checkusername) == 0 &amp;&amp; mysql_num_rows($checkemail) == 0){
  
          mysql_query("INSERT INTO `database`.`user`(`username`,`password`,`email`) VALUES ('".$username."','".$password."','".$email."')") or die(mysql_error());
          ?&gt;&lt;p&gt;&lt;?php echo "You are Registered"; ?&gt;&lt;/p&gt;&lt;?php
      }
      else{
          if(mysql_num_rows($checkusername) &gt; 0){
              $error[] = "Username already exists";
          }
          if(mysql_num_rows($checkemail) &gt; 0){
              $error[] = "Email already exists";
          }
          foreach ($error as $value) {
              ?&gt;&lt;p&gt;&lt;?php echo "'".$value."'&lt;br&gt;"; ?&gt;&lt;/p&gt;&lt;?php
          }
      }
  }
  else{
  
      if(empty($username)){
          $error[] = "Please insert a username";
      }
      if(empty($password)){
          $error[] = "Please insert a password";
      }
      if(empty($email)){
          $error[] = "Please insert a email";
      }
      foreach ($error as $value) {
          ?&gt;&lt;p&gt;&lt;?php echo "'".$value."'&lt;br&gt;"; ?&gt;&lt;/p&gt;&lt;?php
      }
  }
  }
  ?&gt;
  </code></pre>