title: Trying to check if username already exists in MySQL database using PHP
body: <p>I've looked at the many other posts that were similar to my issue and implemented their solutions (as far as I can tell) as exactly as I could. However, every time I execute this script, the code in the else block is executed (even when the username inputted is one that is already present).</p>
  
  <p>The table name is 'Users' and the column that I am trying to search is 'username'.
  The input from my form was read into <code>$username</code> and I verified that it was read in properly using <strong>echo</strong>. <code>$con</code> contains the connection to the server.</p>
  
  <p>At some point I also put in <code>echo $query</code> (nothing was printed) and <code>echo mysql_num_rows($query)</code> (nothing was printed).</p>
  
  <p>Here's the relevant segment of the code. Would really appreciate some tips.</p>
  
  <pre><code>$query = mysql_query("SELECT username FROM Users WHERE username=$username", $con);
  
    if (mysql_num_rows($query) != 0)
    {
        echo "Username already exists";
    }
  
    else
    {
      ...
    }
  </code></pre>
  
  <p>EDIT: Apparently I was supposed to be using mysqli for my server and the way I checked the num_rows for that was by doing $query->num_rows since it was a property of the object. Thanks for all the help!</p>