IAM尝试发布以下JSON数据广东话后的数据在PHP
{"name":"somename","email":"somemail","password":"abcdef"}
在我的API的身体
,
<?php
require_once 'include/DB_Functions.php';
$db = new DB_Functions();
// json response array
$response = array("error" => FALSE);
if (isset($_POST['name']) && isset($_POST['email']) &&
isset($_POST['password'])) {
// receiving the post params
$name = $_POST['name'];
$email = $_POST['email'];
$password = $_POST['password'];
// check if user is already existed with the same email
if ($db->isUserExisted($email)) {
// user already existed
$response["error"] = TRUE;
$response["error_msg"] = "User already existed with " . $email;
echo json_encode($response);
} else {
// create a new user
$user = $db->storeUser($name, $email, $password);
if ($user) {
// user stored successfully
$response["error"] = FALSE;
$response["uid"] = $user["unique_id"];
$response["user"]["name"] = $user["name"];
$response["user"]["email"] = $user["email"];
$response["user"]["created_at"] = $user["created_at"];
$response["user"]["updated_at"] = $user["updated_at"];
echo json_encode($response);
} else {
// user failed to store
$response["error"] = TRUE;
$response["error_msg"] = "Unknown error occurred in registration!";
echo json_encode($response);
}
}
} else {
$response["error"] = TRUE;
$response["error_msg"] = "Required parameters (name, email or password) is
missing!";
echo json_encode($response);
}
?>
我的问题是,if (isset($_POST['name']) && isset($_POST['email']) && isset($_POST['password']))
始终是假的,消息Required parameters (name, email or password) is missing! is shown
在wampserver日志,误差给定为
PHP已弃用:自动填充$ HTTP_RAW_POST_DATA为 弃用,将在未来的版本中删除。为避免这种情况,警告在php.ini中将'always_populate_raw_post_data'设置为'-1',并改为使用 php://输入流。在在线0
'“password”,“abcdef”'应该像其他人一样冒号,* n'est-ce pas * *编辑:此评论按照原帖https://stackoverflow.com/revisions/ 46042691/1 –
是的,那是一个类型错误 –
这是哪里的HTML /表单? –