title: Mysqli check if username already exists
body: <p>Yes I know this has been asked before and I literally copied code from multiple answers from this site trying to get it to work. This is the code I've been using now but it keeps allowing me to enter duplicate entries.</p>
  
  <pre><code>$query = mysqli_query($con, "SELECT * FROM Email WHERE Email = '".$testemail. "'");
  if(mysqli_num_rows($query) &gt; 0){
      echo "Email is already in use.&lt;br&gt;";
  }else{
      $query = mysqli_query($con, "SELECT * FROM Username WHERE Username = '".$testname. "'");
    if(mysqli_num_rows(  $query) &gt; 0){
      echo "Username is already in use.&lt;br&gt;";
  }else{
      $sql = "INSERT INTO users (Username, Password, Email, Firstname, Lastname, Lastlogin, Registered) VALUES ('$testname', '$testpass', '$testemail', '$testfirstname' , '$testlastname', '$lastlogin', '$registered')";
      if ($conn-&gt;query($sql) === TRUE) {
          echo "New account created successfully&lt;br&gt;";
      } 
    }
  }
  </code></pre>
  
  <p>Is the specific code that should stop this from happening but  <a href="http://pastebin.com/trKjtyDA" rel="nofollow noreferrer">here is the full page:</a></p>
  
  <p>First time that I'm working with a login system like this so I wouldn't be surprised if I'm making some stupid mistake.</p>
  
  <p>EDIT: I tried editing it but its still not working, I also made the 'Email' and 'Username' column unique in my database. But all this does is stop the data from being inputed at all. I also tried a workaround where it displays a error at error number 1062 but that happens hasn't worked yet.</p>
  
  <p><a href="http://pastebin.com/yim1B8Fe" rel="nofollow noreferrer">The new code</a></p>
  
  <p>I missed something obvious as well, I'm using a IF statement so it only loops through the fie query check once I think</p>