2017-09-28 9 views
0

httpリクエスタを使用しています。 /エンコードされた値は、値を受け入れることができるブラウザを介しています。httpリクエスタを使用して私はキーと値を送信することができますが、同じURL /エンコードされた値をブラウザで送信しているときに値を受け入れることができました

エラー:

Notice: Undefined index: email in filepath/filename.php on line 7

Notice: Undefined index: password in filepath/filename.php on line 8

Notice: Undefined index: username in filepath/filename.php on line 9

Notice: Undefined index: age in filepath/filename.php on line 10

Notice: Undefined index: gender in filepath/filename.php on line 11

Notice: Undefined index: address in filepath/filename.php on line 12

Notice: Undefined index: city in filepath/filename.php on line 13

Notice: Undefined index: country in filepath/filename.php on line 14

Notice: Undefined index: pincode in filepath/filename.php on line 15

Notice: Undefined index: mobile in filepath/filename.php on line 16

Notice: Undefined index: roleid in filepath/filename.php on line 17

{"status":"error","message":"Missing required field"}

マイコード:以下 thrwingエラー

<?php 


require("Conn.php"); 
require("MySQLDao.php"); 

$email = $_POST["email"]; 
$password = $_POST["password"]; 
$username = $_POST["username"]; 
$age = $_POST["age"]; 
$gender = $_POST["gender"]; 
$address = $_POST["address"]; 
$city = $_POST["city"]; 
$country = $_POST["country"]; 
$pincode = $_POST["pincode"]; 
$mobile = $_POST["mobile"]; 
$roleid = $_POST["roleid"]; 

$returnValue = array(); 

if(empty($email) || empty($password) || empty($username) || empty($pincode) || empty($gender) || empty($mobile)) 
{ 
$returnValue["status"] = "error"; 
$returnValue["message"] = "Missing required field"; 
echo json_encode($returnValue); 
return; 
} 

$dao = new MySQLDao(); 
$dao->openConnection(); 
$userDetails = $dao->getUserDetails($email); 

if(!empty($userDetails)) 
{ 
$returnValue["status"] = "error"; 
$returnValue["message"] = "User already exists"; 
echo json_encode($returnValue); 
return; 
} 

$secure_password = md5($password); // I do this, so that user password cannot be read even by me 

$result = $dao->registerUser($email,$secure_password,$username,$age,$gender,$address,$city,$country,$pincode,$mobile,$roleid); 

if($result) 
{ 
$returnValue["status"] = "Success"; 
$returnValue["message"] = "User is Registered"; 
echo json_encode($returnValue); 
return; 
} 

$dao->closeConnection(); 

?> 

答えて

1

$ _REQUESTを使用して、$ _GETおよび$ _POSTリクエストよりも優れた投稿データを取得できます。例: $ email = $ _REQUEST ['email'];

OR

いくつかのタイムサーバーは、モバイルデバイスサービスからポストされたデータとしてポストデータを処理していないあなたは、以下のかもしれないよりも、体の要求を通知:

$ JSON =のfile_get_contents(「PHP://入力」) ; $ obj = json_decode($ json、TRUE);

+0

解決エラー[ 'メール'];? – Devendra

0

あなたがブラウザを介して送信しているとき、それはGETメソッド($ _GET)を使用しますので、それはだ...

を投稿しません

あなたの$ _POSTは空です($ _POST ["email"]の未定義インデックス)

POSTでフォームを使用して送信することができます。

0

このエラーが発生する理由は2つあります。まず、ステートメントにコードをラップして、リクエストを送信する前に$_POSTから変数を割り当てようとします。 if($_SERVER['REQUEST_METHOD'] == 'POST'){ //your code、そしてもう1つは、@parparが述べたように、メソッドが必要な間に、GETリクエストを送信するかもしれません。

1

また、isset()関数による例外処理では、次のように使用することもできます。 CODE:$メール= $ _REQUESTを使用して

<?php 
require("Conn.php"); 
require("MySQLDao.php"); 
$email=isset($_POST["email"])&&$_POST["email"]!=NULL?$_POST["email"]:""; 
$password=isset($_POST["password"])&&$_POST["password"]!=NULL?$_POST["password"]:""; 
$username=isset($_POST["username"])&&$_POST["username"]!=NULL?$_POST["username"]:""; 
$age=isset($_POST["age"])&&$_POST["age"]!=NULL?$_POST["age"]:""; 
$gender=isset($_POST["gender"])&&$_POST["gender"]!=NULL?$_POST["gender"]:""; 
$address=isset($_POST["address"])&&$_POST["address"]!=NULL?$_POST["address"]:""; 
$city=isset($_POST["city"])&&$_POST["city"]!=NULL?$_POST["city"]:""; 
$country=isset($_POST["country"])&&$_POST["country"]!=NULL?$_POST["country"]:""; 
$pincode=isset($_POST["pincode"])&&$_POST["pincode"]!=NULL?$_POST["pincode"]:""; 
$mobile=isset($_POST["mobile"])&&$_POST["mobile"]!=NULL?$_POST["mobile"]:""; 
$roleid=isset($_POST["roleid"])&&$_POST["roleid"]!=NULL?$_POST["roleid"]:""; 
$returnValue = array(); 

if(empty($email) || empty($password) || empty($username) || empty($pincode) || empty($gender) || empty($mobile)) 
{ 
$returnValue["status"] = "error"; 
$returnValue["message"] = "Missing required field"; 
echo json_encode($returnValue); 
return; 
} 

$dao = new MySQLDao(); 
$dao->openConnection(); 
$userDetails = $dao->getUserDetails($email); 

if(!empty($userDetails)) 
{ 
$returnValue["status"] = "error"; 
$returnValue["message"] = "User already exists"; 
echo json_encode($returnValue); 
return; 
} 

$secure_password = md5($password); // I do this, so that user password cannot be read even by me 

$result = $dao->registerUser($email,$secure_password,$username,$age,$gender,$address,$city,$country,$pincode,$mobile,$roleid); 

if($result) 
{ 
$returnValue["status"] = "Success"; 
$returnValue["message"] = "User is Registered"; 
echo json_encode($returnValue); 
return; 
} 

$dao->closeConnection(); 

>

+0

これは私のために働いた – Devendra

+0

しかし、今私はブラウザから値を掲示しているときに "{"状態 ":"エラー "、"メッセージ ":"必須フィールドが見つかりません "}" これに感謝、httpリクエスタを使用して、値が挿入されます – Devendra

関連する問題