php post方法返回404错误


php post method return 404 error

当我测试php-post方法时,我面临一些问题。服务器将始终返回404错误。我不知道是不是我的配置问题。但当我把它变成get方法时,我可以得到我想要的所有参数。

我的环境是:phpstorm+examplep

    <html>
<body>
<form method="post">
    Name: <input type="text" name="name"><br>
    E-mail: <input type="text" name="email"><br>
    <input type="submit">
    Welcome <?php echo $_POST["name"]; ?><br>
    Your email address is: <?php echo $_POST["email"]; ?>
</form>
</body>
</html>

听起来像是直接在浏览器中访问文件文件,而不是通过HTTP服务器。

网址是什么?

如果是类似file://path/to/file.php这是行不通的,它需要http://localhost/path/to/file.php

您可能需要指定action并检查$POST是否为isset,类似于:

<form method="post" action="<?php echo htmlentities($_SERVER['PHP_SELF']);?>" >
    Name: <input type="text" name="name"><br>
    E-mail: <input type="text" name="email"><br>
    <input type="submit">
    <br>
<?php
    if(isset($_POST["name"]) and isset($_POST["email"]))
    {
        echo "Welcome". $_POST["name"] . "<br>";
        echo "Your email address is: " .  $_POST["email"];
    }
?>
</form>

注意:

确保在安装了php并正确运行的服务器上运行上述代码。