无法获取 php 中的 $_POST 值,但 $_GET 可以
can not get the $_POST value in php ,but $_GET is ok
我使用 PHP 5.6 和 PHPstorm 10。
html 代码如下。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>test</title>
</head>
<body>
<form action="hello.php" method="post">
<input type="text" name="blabla">
<input type="submit">
</form>
</body>
</html>
PHP 代码在 .
之后
<?php
echo $_POST["blabla"];
?>
但是如果我把方法改成GET
。
这将是工作。但是我无法获得 post 值。
然后我安装WAMP Server.when 只是用WAMP Server 来访问,它worked.why?为什么我不能用PHPStorm 来获取post 值。
您需要通过以下方式检查 "Request Type":-
$method = $_SERVER['REQUEST_METHOD'];
if ($method == 'POST') {
// Method is POST
echo "post";
$data = isset($_POST["blabla"]) ? $_POST["blabla"] : 'notset';
echo $data; // print data
} elseif ($method == 'GET') {
// Method is GET
echo "get";
} else {
// Method unknown may be put or delete
echo "unknown";
}
希望对您有所帮助:)
删除表格method = "post"
PHP 代码在 .
之后
<?php
echo $_REQUEST["blabla"];
?>
我使用 PHP 5.6 和 PHPstorm 10。
html 代码如下。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>test</title>
</head>
<body>
<form action="hello.php" method="post">
<input type="text" name="blabla">
<input type="submit">
</form>
</body>
</html>
PHP 代码在 .
之后<?php
echo $_POST["blabla"];
?>
但是如果我把方法改成GET
。
这将是工作。但是我无法获得 post 值。
然后我安装WAMP Server.when 只是用WAMP Server 来访问,它worked.why?为什么我不能用PHPStorm 来获取post 值。
您需要通过以下方式检查 "Request Type":-
$method = $_SERVER['REQUEST_METHOD'];
if ($method == 'POST') {
// Method is POST
echo "post";
$data = isset($_POST["blabla"]) ? $_POST["blabla"] : 'notset';
echo $data; // print data
} elseif ($method == 'GET') {
// Method is GET
echo "get";
} else {
// Method unknown may be put or delete
echo "unknown";
}
希望对您有所帮助:)
删除表格method = "post"
PHP 代码在 .
之后<?php
echo $_REQUEST["blabla"];
?>