PHP displaying error for already used Username and empty field

Posted by Pixel Reaper on Stack Overflow See other posts from Stack Overflow or by Pixel Reaper
Published on 2012-11-30T16:55:04Z Indexed on 2012/11/30 17:03 UTC
Read the original article Hit count: 177

Filed under:
|
|
|
|

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.';
            }

© Stack Overflow or respective owner

Related posts about php

Related posts about mysql