don´t recognize variable of php

前端 未结 2 536
死守一世寂寞
死守一世寂寞 2021-01-29 16:38

I have the following code in two files separately

file one.php



Age:
相关标签:
2条回答
  • 2021-01-29 16:59

    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.

    0 讨论(0)
  • 2021-01-29 17:07

    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>
    
    0 讨论(0)
提交回复
热议问题