有关php 相同的表单,get方法可以获取数据而post却不能

来源:百度知道 编辑:UC知道 时间:2024/06/21 17:51:05
<form action="#" method="post">
Name: <input type="text" name="name" />
Age: <input type="text" name="age" />
<input type="submit" />
</form>
<?php echo "Name:".htmlspecialchars($_POST["name"])."<br/>Age:".(int)$_POST["age"]; ?>
上面这样放在同一个页面可以正常获取数据,但是下面把get改成post 的时候
form_get.php页面却显示的是: Hi . You are 0 years old
请问这是为什么呢?
<form action="form_get.php" methhod="GET">
<p>Your 姓名: <input type="text" name="name" /></p>
<p>your 年龄: <input type="text" name="age" /></p>
<p><input type="submit" /></p>
</form>
form_get.php:
Hi <?php echo htmlspecialchars($_GET["name"]); ?>.
You are <?php echo (int)$_GET[age]; ?&

method写成methhod了,还有$_GET[age]中age要加引号。另外,你为什么要把age转换成int再输出呢?php会在需要的时候自己转换的,况且,只做输出的话没必要转换成整型。

methhod="GET
method拼写都有问题

<form action="form_get.php" methhod="GET">
method多了个h啊