mysql必填字段,必填字段缺少结果mysql下载starting the server
I'll just keep this question short. What is wrong with my php code, it keeps outputting 0 or Required Field(s) is missing. Here's the code
// 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);
}
>
Here is the post data in my app
protected String args) {
/
/ TODO Auto-generated method stub
// Check for success tag
int success;
String status_id = Text().toString();
try {
// Building Parameters
List params = new ArrayList();
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", String());
// json success element
success = Int(TAG_SUCCESS);
if (success == 1) {
Log.d("Updated!", String());
finish();
String(TAG_MESSAGE);
}else{
Log.d("Update Failure!", String(TAG_MESSAGE));
String(TAG_MESSAGE);
}
} catch (JSONException e) {
e.printStackTrace();
}
return null;
}
Any answers will be very much honored :D Thanks!
解决⽅案
Your error says it all. Since you get to the } else { ... } bit, it means isset($_POST['id']) && isset($_POST['status_id']) is false. In other words, your form is either:
not using POST, but GET. In that case add method="post" to your
tag. (actually, POST is default behaviour, so if this is the case, you probably have to remove or change method="GET" from the form tag)
and/or your form does not contain input fields with name="id" and/or name="status_id"
The updated question adds Android code. Hence this update:
I doubt that jsonParser.makeHttpRequest actually posts a form encoded json string. It more then likely will just POST json data to the webserver. PHP's $_POST will not automatically be filled with this data, since it only handles form encoded data.
You probably need to read this data from stdIn.
Try:
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$rawPostData = file_get_contents("php://input");
$postData = (array)json_decode($rawPostData);
}
And then use $postData where you otherwise would use $_POST

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。