frank_solo Posted March 17, 2011 Share Posted March 17, 2011 I have written the code for email check, but how and where can I put the code to check if a username has been used twice? Thanks in advance. <?php $servername = "localhost"; $username = ""; $password = ""; //validate fields if(!$_POST["username"] || !$_POST["email"] || !$_POST["password1"] || !$_POST["password2"]){ echo "<p> </p><p> </p><p> </p><br />Please fill the required fields, <p> </p><p> </p><a href='register.php'>Go to register page</a>"; //validate password }else if($_POST["password1"] != $_POST["password2"]){ echo "<p> </p><p> </p><p> </p><br />Please go back, PASSWORDS do not match! <p> </p><p> </p><a href='register.php'>Go to register page</a>"; //validate email }else if(!(eregi("^.+@.+\\..+$", $_POST['email']))){ echo "<p> </p><p> </p><p> </p><br />Please enter a valid EMAIL! <a href='register.php'><p> </p><p> </p>Go to register page</a>"; //validate captcha }else if(($_SESSION['security_code'] != $_POST['security_code']) || (empty($_SESSION['security_code'])) ){ echo "<p> </p><p> </p><p> </p><br />CAPTCHA CODE does not match! <p> </p><p> </p><a href='register.php'>Go to register page</a>"; }else{ $conn= mysql_connect($servername,$username,$password)or die(mysql_error()); mysql_select_db("genesis_members",$conn); // check if already registered $sql_check = "SELECT * FROM users WHERE email = '".$_POST[email]."'"; $result_check = mysql_query($sql_check,$conn) or die(mysql_error()); $row = mysql_fetch_assoc($result_check); if($row['id']){ echo "<p> </p><p> </p><p> </p><br />EMAIL already registered! <p> </p><p> </p><a href='register.php'>Go to register page</a>"; }else{ // insert in db $sql = "INSERT INTO users (username, email, password, company, phone, services) VALUES ('".$_POST[username]."', '".$_POST[email]."', '".$_POST[password1]."', '".$_POST[company]."', '".$_POST[phone]."', '".$_POST[services]."')"; $result = mysql_query($sql,$conn) or die(mysql_error()); echo "<p> </p><p> </p><p> </p><br /><h1>You Have Successfully Registered</h1>"; echo "<p> </p><p> </p><br /><a href='main_login.php'>go to login page</a>"; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/230961-checking-if-a-username-has-been-used-twice/ Share on other sites More sharing options...
requinix Posted March 17, 2011 Share Posted March 17, 2011 Copy the stuff you did for emails, but replace email-related stuff with username-related stuff. Quote Link to comment https://forums.phpfreaks.com/topic/230961-checking-if-a-username-has-been-used-twice/#findComment-1188903 Share on other sites More sharing options...
frank_solo Posted March 17, 2011 Author Share Posted March 17, 2011 For some reason I was thinking elseif statement. Thank you for the help. Another question how can I limit password to 6 to 8 character? Quote Link to comment https://forums.phpfreaks.com/topic/230961-checking-if-a-username-has-been-used-twice/#findComment-1188910 Share on other sites More sharing options...
Eyewash01 Posted March 17, 2011 Share Posted March 17, 2011 Use the strlen($string) function to check length of the password http://php.net/manual/en/function.strlen.php Quote Link to comment https://forums.phpfreaks.com/topic/230961-checking-if-a-username-has-been-used-twice/#findComment-1188943 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.