Okay, I have another problem, the code is fixed now:
{
//Check if user already exists
$un_check = mysql_query("SELECT Username FROM users WHERE Username = '$un'");
if(mysql_num_rows($un_check) >0) {
echo "Username already exists";
}
else{
// Username Free
}
But the database still allows usernames to be the same. Also, even though it says "username already exists" I still creates the account anyway?
any ideas?
try this
$un_check = mysql_query("SELECT Username FROM users WHERE Username = 'POSTVALUE'");
if(mysql_num_rows($un_check) >0) {
echo "Username is taken";
}
else{
// Username Free
}
Seems typo change $un
to $un_check
,
if(mysql_num_rows($un_check) >0) {...
Always have your PHP errors turn on at-least on development environment,
error_reporting(E_ALL);
Note: Please, don't use mysql_*
functions in new code. They are no longer maintained and are officially deprecated. See the red box? Learn about prepared statements instead, and use PDO, or MySQLi - this article will help you decide which. If you choose PDO, here is a good tutorial.
Change this :-
if(mysql_num_rows($un) >0)
to
if(mysql_num_rows($un_check) >0)