为什么此代码不再显示我的文本框的值?

Har*_*ris 2 php

我是PHP的初学者.2天前我写了几行代码,但昨天已经不行了.代码是:

<body>
    <form method='post' action='test.php'>
        name <input type='text' id='txtName'/>
        age <input type='text' id='txtAge'/>
        <input type='submit'/>
        <hr/>
        name <?php echo $_POST['txtName']; ?>
        age <?php echo $_POST['txtAge']; ?>
    </form>
</body>
Run Code Online (Sandbox Code Playgroud)

它的作用只是显示文本框的值,但它不起作用.为什么?

Chr*_*ris 5

在输入标签上使用name属性而不是php post变量的ID:

<body>
<form method='post' action='test.php'>
    name <input type='text' name='txtName'/>
    age <input type='text' name='txtAge'/>
    <input type='submit'/>
    <hr/>
    name <?php echo $_POST['txtName']; ?>
    age <?php echo $_POST['txtAge']; ?>
</form>
Run Code Online (Sandbox Code Playgroud)