PHP displaying error for already used Username and empty field
- by Pixel Reaper
I want PHP to make sure the username is not already used and also check to see if the field is empty. Sorry I am a huge noob when it comes to php. Here is my code:
// Check for an Username:
$dup = mysql_query("SELECT user_username FROM users WHERE user_username='".$_POST['user_username']."'");
if(mysql_num_rows($dup) >0){
$errors[] = 'Username already used.';
}
else{
$un = mysqli_real_escape_string($dbc, trim($_POST['user_username']));
echo '<b>Congrats, You are now Registered.</b>';
}
else {
$errors[] = 'You forgot to enter your Username.';
}