我只是簡單地說這個問題。我的php代碼有什麼問題,它一直輸出0或必填字段(s)缺失。下面的代碼必填字段missing results
<?php
// array for JSON response
$response = array();
// check for required fields
if (isset($_POST['id']) && isset($_POST['status_id'])) {
$id = $_POST['id'];
$status_id = $_POST['status_id'];
// include db connect class
require_once __DIR__ . '/db_connect.php';
// connecting to db
$db = new DB_CONNECT();
// mysql update row with matched pid
$result = mysql_query("UPDATE pims_liip_pallet_purchase_order SET status = '$status_id' WHERE id = $id");
// check if row inserted or not
if ($result) {
// successfully updated
$response["success"] = 1;
$response["message"] = "Product successfully updated.";
// echoing JSON response
echo json_encode($response);
} else {
}
} else {
// required field is missing
$response["success"] = 0;
$response["message"] = "Required field(s) is missing";
// echoing JSON response
echo json_encode($response);
}
?>
這裏是POST數據在我的應用程序
protected String doInBackground(String... args) {
// TODO Auto-generated method stub
// Check for success tag
int success;
String status_id = statusID.getText().toString();
try {
// Building Parameters
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("status_id", status_id));
Log.d("request!", "starting");
//Posting user data to script
JSONObject json = jsonParser.makeHttpRequest(
UPDATE_COMMENTS_URL, "POST", params);
// full json response
Log.d("Post Update", json.toString());
// json success element
success = json.getInt(TAG_SUCCESS);
if (success == 1) {
Log.d("Updated!", json.toString());
finish();
return json.getString(TAG_MESSAGE);
}else{
Log.d("Update Failure!", json.getString(TAG_MESSAGE));
return json.getString(TAG_MESSAGE);
}
} catch (JSONException e) {
e.printStackTrace();
}
return null;
}
任何答案將非常榮幸:d謝謝!
print_r($ _ POST)並查看從窗體獲得的參數是什麼。您驗證是阻止您提交 – Sundar
由於您沒有收到任何錯誤消息,並且您看到了自己的錯誤消息,因此您期望的兩個參數(id和status_id)中至少有一個缺少 – vkamayiannis
「它始終輸出0或必需字段缺失。「意味着你的情況失敗。爲什麼不能檢查或回顯帖子變量,看看他們是否失蹤 –