"SELECT username FROM users WHERE username='" . $username . "'"
não
"SELECT username FROM users WHERE username='' . $username . ''"
Mas considere mudar para instruções parametrizadas com mysqli ou pdo
"SELECT username FROM users WHERE username='" . $username . "'"
"SELECT username FROM users WHERE username='' . $username . ''"