Your code assumes the existence of something:
$user = $_POST["username"];
PHP is letting you know that there is no "username" in the $_POST
array. In this instance, you would be safer checking to see if the value isset()
before attempting to access it:
if ( isset( $_POST["username"] ) ) {
/* ... proceed ... */
}
Alternatively, you could hi-jack the ||
operator to assign a default:
$user = $_POST["username"] || "visitor" ;
As long as the user's name isn't a falsy value, you can consider this method pretty reliable. A much safer route to default-assignment would be to use the ternary operator:
$user = isset( $_POST["username"] ) ? $_POST["username"] : "visitor" ;