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']))));
}
}
Dan McGrath
42.1k11 gold badges104 silver badges130 bronze badges
-
possible duplicate of stackoverflow.com/questions/2650043/…Ben S– Ben S2010年04月16日 03:03:59 +00:00Commented Apr 16, 2010 at 3:03
-
Please re-phrase the question.... What you are asking is not very clear...SpikETidE– SpikETidE2010年04月16日 04:05:02 +00:00Commented Apr 16, 2010 at 4:05
-
its okay I solved it myself, thanks though.peakUC– peakUC2010年04月16日 04:13:03 +00:00Commented Apr 16, 2010 at 4:13
2 Answers 2
This should do the trick: <input type="hidden" name="username" value="somevalue"/>.
answered Apr 16, 2010 at 3:09
Jacob Relkin
164k34 gold badges352 silver badges321 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
if You did not want to fill your name in form then use hidden fied then use hidden field
answered Apr 20, 2010 at 6:25
Kanak Vaghela
8,48810 gold badges34 silver badges38 bronze badges
Comments
default