PHP & MySQL form question.

Posted by peakUC on Stack Overflow See other posts from Stack Overflow or by peakUC
Published on 2010-04-16T02:59:20Z Indexed on 2010/04/16 3:03 UTC
Read the original article Hit count: 231

Filed under:
|

How do I allow all users to have there username field empty without having them to enter a username when they submit the form using PHP and MySQL?

Here is part my PHP and MySQL code.

$username = mysqli_real_escape_string($mysqli, $purifier->purify(htmlentities(strip_tags($_POST['username']))));


if(isset($_POST['username'])) {
    // Make sure the username address is available:
    $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