PHP & MySQL username submit problem

Posted by peakUC on Stack Overflow See other posts from Stack Overflow or by peakUC
Published on 2010-04-16T01:31:58Z Indexed on 2010/04/16 1:33 UTC
Read the original article Hit count: 328

Filed under:
|

I want to allow users to either have there username field empty at any time but I get the username error message Your username is unavailable! how can I correct this problem?

Here is the PHP code.

if(isset($_POST['username'])) {

    $u = "SELECT * 
          FROM users 
          WHERE username  = '$username'
          AND user_id <> '$user_id'";
    $r = mysqli_query ($mysqli, $u) or trigger_error("Query: $q\n<br />MySQL Error: " . mysqli_error($mysqli));

    if (mysqli_num_rows($r) == TRUE) { // Unavailable.
        echo '<p class="error">Your username is unavailable!</p>';
        $username = NULL;
    } else if(mysqli_num_rows($r) == 0) { // Available.
        $username = mysqli_real_escape_string($mysqli, $purifier->purify(htmlentities(strip_tags($_POST['username']))));
    }
}

© Stack Overflow or respective owner

Related posts about php

Related posts about mysql