PHP $_POST接受不到数据,但$_GET可以接受数据
大家讲道理
大家讲道理 2017-04-10 18:02:51
[PHP讨论组]

新手一枚,代码如下,把post 改成 get 就没问题,但如果是post 就会提示
Notice: Undefined index: a in D:\xampp\htdocs\myphp\add.php on line 3

add.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<form action="add.php" method="post">
     a:<input type="text" name="a"> <br/>
     b:<input type="text" name="b"><br/>
    <input type="submit" value="提交">

</form>
</body>
</html>

add.php

   <?php
    
    if($_POST['a'] && $_POST['b']){
        echo $_POST['a'] + $_POST['b'];
    }else{
        echo ' 请输入数字';
    }
    ?>
大家讲道理
大家讲道理

光阴似箭催人老,日月如移越少年。

全部回复(8)
大家讲道理

我也是类似的问题,只有一种可能,就是你得phpstrom配置的端口与phpinfo()端口不符。先看一下<?php
phpinfo()?>的端口在哪里比如localhost,那么就配置phpstrom-》Tools-》Dployment-》Configuration-》
新建比如Name=localhost,然后设置Web sever root url为http://localhost,端口与phpinfo()端口一致即可

黄舟

php.ini 中配置 enable_post_data_reading 为 On, 这样才会自动将 POST 数据填入 $_POST 数组中。

; 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
高洛峰

判断是否输入a和b的值,应该使用:

isset($_POST['a']) && isset($_POST['b']

你的写法在a或b输入0值时,不会走相加分支。

PHP中文网

打印 $_REQUEST数组,

天蓬老师

如果查验是否有数据POST过来,如果没有确定的条件下,推荐在业务处理前先进行打印数据。
上面可以直接
var_dump($_POST);
看下是否有值。

阿神

post有好几种方式,你看你是什么方式提交的?

阿神

php配置问题吧

巴扎黑

楼主的问题解决了吗?同样碰到这样的问题

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号