I'm making a username check for php, I need to check if the string is between 3 and 20 characters, I've tried this, but it doesn't work! heres the link to my code sample, I don't know how to work stackoverflow :(
if(isset($_POST['submit'])){
$user = trim(mysql_real_escape_string($_POST['user']));
$email = trim(mysql_real_escape_string($_POST['email']));
$pass1 = trim(mysql_real_escape_string($_POST['pass1']));
$pass2 = trim(mysql_real_escape_string($_POST['pass2']));
if(!empty($user) && !empty($email) && !empty($pass1) && !empty($pass2)){
if(ctype_alnum($user)){
if(filter_var($email, FILTER_VALIDATE_EMAIL)){
if(strlen($user) < 3){
if(strlen($user) > 20){
$query1 = mysql_query("SELECT username FROM users WHERE username='$user'");
$query2 = mysql_query("SELECT email FROM users WHERE email='$email'");
$count1 = mysql_num_rows($query1);
$count2 = mysql_num_rows($query2);
if($count1 == 0 && $count2 == 0){
if($pass1 == $pass2){
} else {
$output = '<div id="output"><header><h1>Error, passwords do not match!</h1><a href="#" onclick="document.getElementById(\'output\').style.display = \'none\';return false;"><i class="fa fa-times"></i></a></header></div>';
}
} else {
$output = '<div id="output"><header><h1>Error, username & email are taken!</h1><a href="#" onclick="document.getElementById(\'output\').style.display = \'none\';return false;"><i class="fa fa-times"></i></a></header></div>';
}
if($count1 == 1){
$output = '<div id="output"><header><h1>Error, username is taken!</h1><a href="#" onclick="document.getElementById(\'output\').style.display = \'none\';return false;"><i class="fa fa-times"></i></a></header></div>';
}
if($count2 == 1){
$output = '<div id="output"><header><h1>Error, email is taken!</h1><a href="#" onclick="document.getElementById(\'output\').style.display = \'none\';return false;"><i class="fa fa-times"></i></a></header></div>';
}
} else {
$output = '<div id="output"><header><h1> CC Error, username must be 3-20 characters!</h1><a href="#" onclick="document.getElementById(\'output\').style.display = \'none\';return false;"><i class="fa fa-times"></i></a></header></div>';
}
} else {
$output = '<div id="output"><header><h1>xx Error, username must be 3-20 characters!</h1><a href="#" onclick="document.getElementById(\'output\').style.display = \'none\';return false;"><i class="fa fa-times"></i></a></header></div>';
}
} else {
$output = '<div id="output"><header><h1>Error, invalid email!</h1><a href="#" onclick="document.getElementById(\'output\').style.display = \'none\';return false;"><i class="fa fa-times"></i></a></header></div>';
}
} else {
$output = '<div id="output"><header><h1>Error, username must be alphanumeric!</h1><a href="#" onclick="document.getElementById(\'output\').style.display = \'none\';return false;"><i class="fa fa-times"></i></a></header></div>';
}
} else {
$output = '<div id="output"><header><h1>Error, missing fields!</h1><a href="#" onclick="document.getElementById(\'output\').style.display = \'none\';return false;"><i class="fa fa-times"></i></a></header></div>';
}
}