首页 文章

php5.6中$ _POST为空

提问于
浏览
3

在堆栈溢出中提交表单后,我尝试了几乎所有与空$ _POST相关的解决方案,但没有一个解决了我的问题 . 我使用wamp服务器并使用phpstorm .

  • 在php.ini中更改了post_max_size和upload_max_filesize的值

  • $ _GET工作正常

  • 尝试使用其他ide和编辑器

  • isset返回false

  • var_dump显示数组为空

  • 已将方法= "post"更改为方法= "POST"
    我的代码:
    main.html中

<html>
<body> 
<form action="welcome.php" method="post">
Name: <input type="text" name="name"><br>
E-mail: <input type="text" name="email"><br>
<input type="submit">
</form>
</body><br>
</html>

的welcome.php

<html>
<body>
Welcome <?php echo $_POST["name"]; ?><br>
Your email address is: <?php echo $_POST["email"]; ?>
</body>
</html>`

错误 -

欢迎

注意:未定义的索引:第4行的C:\ Users \ user \ PhpstormProjects \ tryphp \ welcome.php中的名称

您的电子邮件地址是:

注意:未定义的索引:第5行的C:\ Users \ user \ PhpstormProjects \ tryphp \ welcome.php中的电子邮件

3 回答

  • 0

    在welcome.php中添加为第一行:

    var_dump($_POST);
    

    检查你的帖子是否为空...

  • 0

    通过快速测试,您的代码可以在我的服务器上正常工作 .

    运行PHP配置文件(/etc/php5/apache2/php.ini)我发现这些项目可能值得调查

    ; Whether PHP will read the POST data.
    ; This option is enabled by default.
    ; Most likely, you won't want to disable this option globally. It causes $_POST
    ; and $_FILES to always be empty; the only way you will be able to read the
    ; POST data will be through the php://input stream wrapper. This can be useful
    ; to proxy requests or to process the POST data in a memory efficient fashion.
    ; http://php.net/enable-post-data-reading
    ;enable_post_data_reading = Off
    

    所以进入你的php.ini并搜索enable_post_data_reading,如果你没找到它,手动把它(通常在文件的末尾)并确保它是On

    enable_post_data_reading = On
    

    My Version Information:

    PHP 5.5.9-1ubuntu4.17 (cli) (built: May 19 2016 19:05:57)
    Copyright (c) 1997-2014 The PHP Group
    Zend Engine v2.5.0, Copyright (c) 1998-2014 Zend Technologies
    with Zend OPcache v7.0.3, Copyright (c) 1999-2014, by Zend Technologies
    

    如果您仍然没有得到任何结果,请查看您的访问日志 . 它应该显示POST请求进入您的服务器;

    255.255.255.255 - - [13/Sep/2016:10:16:00 -0400] "POST /stackoverflow/welcome.php HTTP/1.1" 200 1226 "http://255.255.255.255/stackoverflow/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/255.255.255.255 Safari/537.36"
    

    (忽略IP地址信息,我编辑它以保护我的服务器:))

    如果它没有显示POST请求,那么这就是一个地方开始 .

    你也可以在你的浏览器上按F12(或者按c键切换i)打开调试控制台,点击网络(在顶部)在你的表单上,点击提交按钮,你会看到一个网络请求熄灭 . 单击它,单击“ Headers ”,滚动到底部,然后查看浏览器实际发送到服务器的信息 .

    希望这个地段的东西可以帮到你 . 请告诉我们:)

  • 0

    如果您在这些字段中提供任何输入,则您的代码需要工作 . 选中此项,命名提交按钮,然后在提交该按钮,表单将转到Welcome.php

    Main.html

    <html>
    <body> 
        <form action="welcome.php" method="POST">
            Name: <input type="text" name="name"><br>
            E-mail: <input type="text" name="email"><br>
            <input type="submit" name="submitForm">
        </form>
    </body>
    </html>
    

    welcome.php

    <html>
    <body>
        <?php 
        $name = "";
        $email = "";
        if (isset($_POST["submitForm"])) {
            $name = $_POST["name"];
            $email = $_POST["name"];
        }
        ?>
        Welcome <?php echo $name; ?><br>
        Your email address is: <?php echo $email; ?>
    </body>
    </html>
    

    如果字段也是空的,那么你的错误就会消失 .

    如果这不起作用,则 welcome.php 不在 main.html 的同一文件夹中 . 检查..

相关问题