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 /表單? –