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 Quote Link to comment 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. Quote Link to comment 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'; } Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.