What are potential reasons for post variables being empty when accessed in PHP?

One potential reason for post variables being empty when accessed in PHP is that the form method used to submit the data is not set to "post". Another reason could be that the form does not have the correct "name" attribute for the input fields. Additionally, there could be an issue with the PHP configuration or server settings.

<form method="post">
    <input type="text" name="username">
    <input type="submit" value="Submit">
</form>

<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
    $username = $_POST["username"];
    echo "Username: " . $username;
}
?>