PHP & MySQL form question
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']))));
}
}
This should do the trick: <input type="hidden" name="username" value="somevalue"/>
.
if You did not want to fill your name in form then use hidden fied then use hidden field
精彩评论