不能POST php

时间:2017-05-03 08:59:39

标签: php html post root

我有一个非常简单的PHP表单来学习php。我有一个教程的代码。我的HTML是:

<form action="php/learnphp.php" method="post">
    <table border="0">
        <tr>
            <td>Name</td>
            <td align="center">
                <input type="text" name="username" size="30" />
            </td>
        </tr>

        <tr>
            <td>Address</td>
            <td align="center">
                <input type="text" name="streetaddress" size="30" />
            </td>
        </tr>

        <tr>
            <td>City</td>
            <td align="center">
                <input type="text" name="cityaddress" size="30" />
            </td>
        </tr>

        <tr>
            <td colspan="2" align="center">
                <input type="submit" value="Submit" />
            </td>
        </tr>

    </table>
</form>

我的php文件是:

<?php

        $usersName = $_POST['username'];
        $streetAddress = $_POST['streetaddress'];
        $cityAddress = $_POST['cityaddress'];

        echo '<p>Your Information</p>';

        // You can combine variables with text using a .

        echo $usersName. ' lives at </br>';
        echo $streetAddress. ' in </br>';
        echo $cityAddress. '</br></br>';       ?>

如果我按下提交按钮,我会收到一条错误消息:无法发送/php/learnphp.php。

我在根映射中有表单,我的php在一个名为'php'的地图中。我知道这可能很简单,但我似乎无法弄明白。

2 个答案:

答案 0 :(得分:0)

路径文件夹可能不正确。尝试使learnphp.php<yourhtmlfile>.html相同。示例root/learnphp.phproot/<yourhtmlfile>.html。您需要编辑表单操作

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

答案 1 :(得分:0)

你可以试试吗。这对我有用。

my.php

<form action="learnphp.php" method="post">
    <table border="0">
        <tr>
            <td>Name</td>
            <td align="center">
                <input type="text" name="username" size="30" />
            </td>
        </tr>

        <tr>
            <td>Address</td>
            <td align="center">
                <input type="text" name="streetaddress" size="30" />
            </td>
        </tr>

        <tr>
            <td>City</td>
            <td align="center">
                <input type="text" name="cityaddress" size="30" />
            </td>
        </tr>

        <tr>
            <td colspan="2" align="center">
                <input type="submit" value="Submit" name="submit" />
            </td>
        </tr>
   </table>
</form>

learnphp.php

<?php
if(isset($_POST["submit"]))
{
    $usersName = $_POST['username'];
    $streetAddress = $_POST['streetaddress'];
    $cityAddress = $_POST['cityaddress'];

    echo '<p>Your Information</p>';

        // You can combine variables with text using a .

        echo $usersName. ' lives at </br>';
        echo $streetAddress. ' in </br>';
        echo $cityAddress. '</br></br>';     
}
?>