另一个页面中的php变量

时间:2014-10-25 00:55:52

标签: php variables var

我是php新手,我只想回复名字,任何人都可以帮助我!

当我点击提交按钮时,它会重定向到action.php然后我想要 从上一页的表单中回复我的名字。

这是我的代码:

action.php的

<?php

    echo "Great! Thanks" . $s1 . " for responding to our survey" ; 

?>

的index.php

<head>

    <title>Idiot Box Survey</title>
    <meta charset="utf-8">
</head>

<body>

    <form action="action.php" method="post">

        <label>Firstname : </label>
        <input type="text" name="fname"><br><br>

        <label>Lastname : </label>
        <input type="text" name="lname"><br><br>

        <label>Year of birth : </label>
        <input type="date" name="ybirth"><br><br>

        <label>Year at School : </label>
        <input type="date" name="yschool"><br><br>

        <label>When will You Wake up : </label>
        <input type="time" name="wake"><br><br>

        <label>How much time you spend on studying : </label>
        <input type="time" name="study"><br><br>

        <label>How much time you spend on Video games : </label>
        <input type="time" name="vgames"><br><br>

        <label>How much time you spend on tv : </label>
        <input type="time" name="tv"><br><br>

        <label>How much time you spend with family : </label>
        <input type="time" name="family"><br><br>

        <label>How much time you spend with friends : </label>
        <input type="time" name="friends"><br><br>

        <label>When will You Sleep : </label>
        <input type="number" name="sleep"><br><br>

        <button type="submit" name="submit"> Submit Form </button>

    </form>

</body>

3 个答案:

答案 0 :(得分:1)

您的问题似乎缺少

action.php,但不管怎样,您的名字都在$_POST['fname']

答案 1 :(得分:0)

<?php echo $_POST['fname']?>

使用输入的name属性打印其他字段

<?php echo $_POST['lname']?> //for the last name and soo ..

答案 2 :(得分:0)

由于我的修改在其他答案中显然不被接受。而不是在$ s1中调用不存在的php变量,在你的action.php页面上写下这个。

if($_POST["submit"]){
    $fname = $_POST["fname"];
    echo "Great! Thanks" . $fname . " for responding to our survey" ;
}

这允许您的表单将提交的数据传递给所需的脚本。点击提交按钮后,您将看到放入fname输入字段的值。