don´t recognize variable of php

2020-05-10 11:15发布

I have the following code in two files separately

file one.php

<HTML>
<BODY>
<FORM ACTION="two.php" METHOD="POST">
   Age: <INPUT TYPE="text" NAME="age">
   <INPUT TYPE="submit" VALUE="OK">
</FORM>
</BODY>
</HTML>

file dos.php

<HTML>
<BODY>
<?PHP
   print ("The age is: $age");
?>
</BODY>
</HTML>

the age variable is not recognized, someone knows fix?

标签: php action
2条回答
Rolldiameter
2楼-- · 2020-05-10 11:37

Your trying to access the value of age from a page( dos.php) but you posting it to (two.php) and your missing $_POST['age'].

one.php

<HTML>
<BODY>
<FORM ACTION="two.php" METHOD="POST">
Age: <INPUT TYPE="text" NAME="age">
<INPUT TYPE="submit" VALUE="OK">
</FORM>
</BODY>
</HTML>

two.php

<HTML>
<BODY>
<?PHP
$age = $_POST['age'];
print ("The age is: $age");
?>
</BODY>
</HTML>
查看更多
孤傲高冷的网名
3楼-- · 2020-05-10 11:57

It's not recognized because you don't create it. Variables don't magically appear in PHP1. You need to get that value from the $_POST superglobal:

<HTML>
<BODY>
<?PHP
   $age = $_POST['age'];
   print ("The age is: $age");
?>
</BODY>
</HTML>

1 Anymore. They used to when register_globals existed. But that has been obsolete since long before you started coding.

查看更多
登录 后发表回答