2016-08-24 82 views
-3


我在嘗試訪問我的應用程序的註冊頁面時出現問題。我使用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); 
} 

任何人都可以幫我嗎?爲什麼我得到這個錯誤。

+3

您是否試圖對三個變量執行'var_dump();'來查看它們實際包含的內容? – Epodax

+0

@Epodax我得到了NULL消息 – Arta

+0

好吧,這個問題,你永遠不會讓他們成真。 – Epodax

回答

0

$ _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