必需参数
问题描述:
我在尝试访问我的应用程序的注册页面时出现问题。我使用PHP Version 7.0.5
。
网址:http://localhost/project/registration.php
PARAMS:名,电子邮件地址和密码
但可惜的是我得到错误信息Required parameters (name, email or password) is missing!
这是我的代码:必需参数
$registration = new user(DB_HOST, DB_USER, DB_PASSWORD, DB_DATABASE);
// json response
$response = array("error" => FALSE);
$name = (isset($_POST['name'])) ? $_POST['name'] : FALSE;
$email = (isset($_POST['email'])) ? $_POST['email'] : FALSE;
$password = (isset($_POST['password'])) ? $_POST['password'] : FALSE;
if (isset($name) && isset($email) && isset($password)) {
//$name = $_GET['name'];
//$email = $_GET['email'];
//$password = $_GET['password'];
// check if user is already existed with the same email
if ($registration->isUserExisted($email)) {
// already existed
$response["error"] = TRUE;
$response["error_msg"] = "User already existed with " . $email;
echo json_encode($response);
} else {
$user = $registration->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);
}
任何人都可以帮我吗?为什么我得到这个错误。
答
$ _POST总是被设置,但其内容可能为空。
$var = '';
// This will evaluate to TRUE so the text will be printed.
if (isset($var)) {
echo "This var is set so I will print.";
}
由于Epodax提到尝试使用var_dump();
+0
我收到了NULL消息 – Arta
您是否试图对三个变量执行'var_dump();'来查看它们实际包含的内容? – Epodax
@Epodax我得到了NULL消息 – Arta
好吧,这个问题,你永远不会让他们成真。 – Epodax