mikefrederick Posted July 7, 2008 Share Posted July 7, 2008 making a site w/ users. upon signup I want to check if a username is taken and if it is I want to add a 1 to the end of the username, check again, if that one is taken add a 2, and so on until the username is not taken. whats a good approach? Quote Link to comment Share on other sites More sharing options...
gigas10 Posted July 7, 2008 Share Posted July 7, 2008 Well don't do that, just notify the user that the login name is already in use. On your registration page, use this code <?php if( isset($_SESSION['ERRMSG_ARR']) && is_array($_SESSION['ERRMSG_ARR']) && count($_SESSION['ERRMSG_ARR']) >0 ) { echo '<ul class="err"><strong><font size=5>'; foreach($_SESSION['ERRMSG_ARR'] as $msg) { echo '<li>',$msg,'</li>'; } echo '</ul></strong</font>'; unset($_SESSION['ERRMSG_ARR']); } ?> then make a register-exec.php and use this $qry = "SELECT count(*) AS c FROM members WHERE login='$login'"; $result = mysql_query($qry); if($result) { $result_array = mysql_fetch_assoc($result); if($result_array['c'] > 0) { $errmsg_arr[] = 'Login ID already in use'; $errflag = true; } @mysql_free_result($result); } else { die("Query failed"); } And obviously modify the select queries as needed. This last piece of code checks to make sure that none of the required fields are missing, add more if u need. if($login == '') { $errmsg_arr[] = 'Login ID missing'; $errflag = true; } if($password == '') { $errmsg_arr[] = 'Password missing'; $errflag = true; } 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.