开发者

PHP & MySQL username submit problem

开发者 https://www.devze.com 2022-12-26 20:21 出处:网络
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?

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']))));
    }
}

NONE of these examples are working. I want to know how can I let my users have no username?


if(isset($_POST['username']) && trim($_POST['username'])!=='') {

Otherwise, $_POST['username'] will be set even if the form is submitted with an empty field.


if(isset($_POST['username']) && !empty($_POST['username'])) {
...
0

精彩评论

暂无评论...
验证码 换一张
取 消