doublea2k7 Posted April 30, 2008 Share Posted April 30, 2008 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 More sharing options...
colombian Posted April 30, 2008 Share Posted April 30, 2008 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. Link to comment https://forums.phpfreaks.com/topic/103629-how-to-check-if-username-doesnt-exist/#findComment-530668 Share on other sites More sharing options...
hitman6003 Posted April 30, 2008 Share Posted April 30, 2008 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'; } Link to comment https://forums.phpfreaks.com/topic/103629-how-to-check-if-username-doesnt-exist/#findComment-530740 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.