Jump to content

how to check if username doesnt exist


doublea2k7

Recommended Posts

hi im new to the forum and i need help

 

how would i check if a user name doesn't exist i know how to check if user name exits

 

if(mysql_num_rows(mysql_query("SELECT userid FROM plus_signup WHERE userid = '$userid'")

but i don't know how to check if it doesn't exits.

 

plz help

Link to comment
https://forums.phpfreaks.com/topic/103629-how-to-check-if-username-doesnt-exist/
Share on other sites

You just need a "!" (not) in front.

 

Or you can check to see if the response is null.

 

if (mysql_num_rows(etc..etc..) == null)

 

I would separate you query into more lines to make it easier to read.

 

$sql = "SELECT userid FROM plus_signup WHERE userid = '$userid'";

 

That way you can just call it in a function.

 

 

You just need a "!" (not) in front.

 

If you did that you would return all other rows from the database...potentially MANY.

 

Use his second suggestion, however mysql_num_rows will not return null, but will return 0 if no matching rows were found.

 

You could also use a COUNT(username) query...

 

$query = "SELECT COUNT(username) FROM users WHERE username = '" . $username . "'";
$result = mysql_query($query) or die(mysql_error());

if (mysql_result($result, 0) > 0) {
  echo 'That username exists';
} else {
  echo 'That username is free';
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.