You have many problems here. Here are the big ones.
First, and this is the (main) reason you don't get results, you're not actually executing the query. You store a string version of the query that you want to run, but you never execute it with, for example, mysql_query()
. You would need something like this:
// ...
$username_check = "SELECT * FROM users WHERE username = '$username'";
$query = mysql_query($username_check); // this is the new line
if (mysql_num_rows($query) > 0) { // note the parameter change
// ...
Second, you're using the mysql
library. As explained in the big red box in the documentation link above, you shouldn't be using mysql_*
functions at all. The mysql_*
functions are outdated, deprecated, and insecure - they have been removed entirely from modern versions of PHP (version 7.0 and higher). Use MySQLi
or PDO
instead.
Third, you are wide open to SQL injection. You need to use prepared statements, rather than concatenating variables into your query. See How can I prevent SQL injection in PHP?.