0

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
asked Apr 16, 2010 at 2:59
3
  • possible duplicate of stackoverflow.com/questions/2650043/… Commented Apr 16, 2010 at 3:03
  • Please re-phrase the question.... What you are asking is not very clear... Commented Apr 16, 2010 at 4:05
  • its okay I solved it myself, thanks though. Commented Apr 16, 2010 at 4:13

2 Answers 2

2

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

answered Apr 16, 2010 at 3:09
Sign up to request clarification or add additional context in comments.

Comments

0

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

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.