if(isset($_POST['submit'])) {
if(!isset($_POST['userName'])) {
$username = 'Anonymous';
}
else $username = $_POST['userName'];
}
I cannot get the $username to be “Anonymous”? It is either blank or the value of $_POST['userName'].
isset()will return true if the variable has been initialised. If you have a form field with itsnamevalue set touserName, when that form is submitted the value will always be “set”, although there may not be any data in it.Instead,
trim()the string and test its length