【问题标题】:Cannot POST php无法发布 php
【发布时间】:2017-05-03 08:59:39
【问题描述】:

我有一个非常简单的 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>';       ?>

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

我在根地图中有表格,而我的 php 在名为“php”的地图中。我知道这可能很简单,但我似乎无法弄清楚。

【问题讨论】:

  • learnphp.php和html相关文件不一样?
  • 是的,有2个文件:第一个是带有表单的html,第二个是learnphp.php
  • learnphp.php 在文件夹 php 中吗?你能分享两个文件的位置吗
  • 它们在同一个文件夹中吗?
  • 验证你的html表单中的action属性路径是否正确。

标签: php html post root


【解决方案1】:

可能是路径文件夹不正确。试着让它像learnphp.php&lt;yourhtmlfile&gt;.html 相同级别。例如root/learnphp.phproot/&lt;yourhtmlfile&gt;.html。你需要编辑你的表单动作

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

【讨论】:

  • 我试过了,但我得到了同样的错误。我已将表单操作更改为“learnphp.php”
  • 我不确定这个是否可以提供帮助,但请尝试一下。为您的表单和提交按钮添加名称。
  • 我尝试了您的代码并在我的本地进行了测试,它可以正常工作。好奇怪
【解决方案2】:

你能试试这个吗。它对我有用。

我的.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>';     
}
?>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-10-05
    • 2021-05-13
    • 1970-01-01
    • 2019-01-10
    • 2018-06-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多