首页 > PHP $_POST接受不到数据,但$_GET可以接受数据

PHP $_POST接受不到数据,但$_GET可以接受数据

新手一枚,代码如下,把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 ' 请输入数字';
    }
    ?>

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


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


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


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

php配置问题吧


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


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

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

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


打印 $_REQUEST数组,

【热门文章】
【热门文章】