-2

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?

user2517092
  • 35
  • 1
  • 6

3 Answers3

2

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.

Zoe
  • 27,060
  • 21
  • 118
  • 148
Rikesh
  • 26,156
  • 14
  • 79
  • 87
0

Change this :-

if(mysql_num_rows($un) >0)

to

if(mysql_num_rows($un_check) >0)
Vivek Sadh
  • 4,230
  • 3
  • 32
  • 49
0

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
}
Fallen
  • 4,435
  • 2
  • 26
  • 46
Nisarg
  • 3,024
  • 5
  • 32
  • 54