Daleeburg Posted March 22, 2007 Share Posted March 22, 2007 As part of the user registration, I would like to make it so that it will check the database and tell me if the name has been used before, and if it has it will kick out an error message. Is there any easy way to do this because the way i tried failed miserably. ~d Link to comment https://forums.phpfreaks.com/topic/43873-solved-stopping-repeats/ Share on other sites More sharing options...
Kerblam Posted March 22, 2007 Share Posted March 22, 2007 Of course, this is an easy thing to do. You just need to use a select query beforehand to find any match where a username is equal to the input username variable, like so: require_once ('connect.php'); # Connect to the database $query = "SELECT * FROM users WHERE username='".$username."'"; $result = @mysql_query ($query); $num = mysql_num_rows ($result); # How many results have that username if ($num > 0) { # The username is in use, so...send an error } } else { # The username isnt in use, carry on } You'll probably need to change around the variable and field names, but that should work. Link to comment https://forums.phpfreaks.com/topic/43873-solved-stopping-repeats/#findComment-212975 Share on other sites More sharing options...
Daleeburg Posted March 22, 2007 Author Share Posted March 22, 2007 thanks, well i guess i wasnt that far off, i should have numbered the rows and i would have exactly what you have. Thanks ~d Link to comment https://forums.phpfreaks.com/topic/43873-solved-stopping-repeats/#findComment-212980 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.