2016-08-24 6 views
-3


私のアプリケーションの登録ページにアクセスしようとすると問題が発生します。私はPHP Version 7.0.5を使用します。
URL: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

3つの変数に 'var_dump();'を実行して実際に何が含まれているか確認しましたか? – Epodax

+0

@エポダクス私は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."; 
} 

言い換えれば、エポダックスはvar_dump()を使ってみてください。

+0

私はNULLメッセージを受け取った – Arta

関連する問題