x
 
<!DOCTYPE html>
<html>
<body>
<form method="post" action="<?php echo $_SERVER['PHP_SELF'];?>">
  名字:<input type="text" name="fname">
  <input type="submit">
</form>
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
    // 收集输入字段的值
    $name = $_POST['fname'];
    if (empty($name)) {
        echo "名字没有填写";
    } else {
        echo $name;
    }
}
?>
</body>
</html>