-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 stands with Ukraine
  • 25,310
  • 18
  • 114
  • 149
Rikesh
  • 25,621
  • 14
  • 77
  • 86
0

Change this :-

if(mysql_num_rows($un) >0)

to

if(mysql_num_rows($un_check) >0)
Vivek Sadh
  • 4,190
  • 2
  • 29
  • 47
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,337
  • 2
  • 25
  • 43
Napster
  • 2,580
  • 4
  • 30
  • 52