chris_rulez001 Posted June 14, 2007 Share Posted June 14, 2007 hi, can i have some help with my code? i would like to be able to check whether the requested username is in use, can this be done? my code: <?php $email = $_POST['email'] ; $first = $_POST['nameFirst'] ; $last = $_POST['nameLast'] ; $username = $_POST['username'] ; $password = $_POST['password'] ; $cpassword = $_POST['cpassword'] ; $age = $_POST['age'] ; $gender = $_POST['gender'] ; $ip=$_SERVER['REMOTE_ADDR']; //check first name if ($first == "") { echo "<strong>Error:</strong><br> You havent entered your first name<br/><br/>"; } //check last name elseif ($last == "") { echo "<strong>Error:</strong><br> You havent entered your last name<br/><br/>"; } //check username elseif ($username == "") { echo "<strong>Error:</strong><br> You havent entered your username<br/><br/>"; } //check if username is in use //check password elseif ($password == "") { echo "<strong>Error:</strong><br> You havent entered your password<br/><br/>"; } //check if confirmed password correctly elseif (strpos($cpassword, $password) === FALSE) { echo "<strong>Error:</strong><br> You havent confirmed your password properly<br/><br/>"; } //check email elseif ($email == "" || strpos($email, "@") === FALSE || strpos($email, ".") === FALSE) { echo "<strong>Error:</strong><br> You havent entered your email<br/><br/>"; } //check age elseif ($age == "" || $age < 13) { echo "<strong>Error:</strong><br> You must be 13 or over to join<br/><br/>"; } //check age elseif ($age == "Age (e.g. 14)" || $age == "") { echo "<strong>Error:</strong><br> You havent entered your age<br/><br/>"; } else { include ('includes/mysql_connect_users.php'); $mysqlinsert="INSERT INTO users(username, password, email, firstname, lastname, age, gender, ip)VALUES('$username', '$password', '$email', '$first', '$last', '$age', '$gender', '$ip')"; $result2=mysql_query($mysqlinsert); if($result2){ echo "<u><strong>Your Login Information</strong></u><br/><br/>"; echo "Your Registered Username Is: ".$username."<br/><br/>"; echo "Your Registered Password Is: ".$password."<br/><br/>"; echo "<u><strong>Other Information</strong></u><br/><br/>"; echo "Your Registered Email Is: ".$email."<br/><br/>"; echo "Your Registered Age Is: ".$age." Years Of Age<br/><br/>"; echo "You Are Successfully Registered, Click <a href='index.php'>Here</a><br/>"; echo " To Go To The Homepage"; echo "<div class='important'><strong><u>Write This Information Down</u></strong></div>"; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/55574-solved-php-help-with-adding-user/ Share on other sites More sharing options...
soycharliente Posted June 14, 2007 Share Posted June 14, 2007 SELECT username FROM user_table WHERE username='$user' if($result) { In use. } else { Not in use. } I don't know how your table/fields is/are set up, but yeah. Quote Link to comment https://forums.phpfreaks.com/topic/55574-solved-php-help-with-adding-user/#findComment-274572 Share on other sites More sharing options...
simcoweb Posted June 14, 2007 Share Posted June 14, 2007 Another way: $sql= "SELECT username FROM user_table WHERE username='$user'"; $result = mysql_query($sql) or die(mysql_error()); if($result) { echo "In use. Try again."; } else { echo = "Not in use. Congrats!"; } Quote Link to comment https://forums.phpfreaks.com/topic/55574-solved-php-help-with-adding-user/#findComment-274573 Share on other sites More sharing options...
chris_rulez001 Posted June 14, 2007 Author Share Posted June 14, 2007 thanks for your help Quote Link to comment https://forums.phpfreaks.com/topic/55574-solved-php-help-with-adding-user/#findComment-274579 Share on other sites More sharing options...
soycharliente Posted June 14, 2007 Share Posted June 14, 2007 Another way: $sql= "SELECT username FROM user_table WHERE username='$user'"; $result = mysql_query($sql) or die(mysql_error()); if($result) { echo "In use. Try again."; } else { echo = "Not in use. Congrats!"; } That's the same thing I said! Quote Link to comment https://forums.phpfreaks.com/topic/55574-solved-php-help-with-adding-user/#findComment-274586 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.