tags:

views:

45

answers:

2

How do I allow all users to have their username field empty without having them need 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']))));
    }
}
+1  A: 

This should do the trick: <input type="hidden" name="username" value="somevalue"/>.

Jacob Relkin
A: 

Hello,

if You did not want to fill your name in form then use hidden fied then use hidden field

Kanak Vaghela