The reason why your query won't work is because your are wrapping the column name and table name with single quotes. They are identifiers and not string literals so they shouldn't be wrap with single quote.
SELECT COUNT(id) FROM users WHERE username = '$username'
If it happens that the column names and tables names used are a reserved keyword, they can be escape with backticks not with single quotes.
In this case, the backticks aren't required since none of them are reserved keywords.
Other links:
As a sidenote, the query is vulnerable with SQL Injection
if the value(s) of the variables came from the outside. Please take a look at the article below to learn how to prevent from it. By using PreparedStatements
you can get rid of using single quotes around values.