当我阅读响应时,我总是从 PHP 收到错误消息:查询中缺少参数。我知道 PHP 和查询 100% 很好,因为它可以工作。只会以这种方式发生。
Volley.class
JSONObject params = new JSONObject();
params.put("consulta", "UPDATE Usuarios SET Nombre='AAA' WHERE IdUsuario=1");
//All right
RequestFuture<JSONObject> future = RequestFuture.newFuture();
JsonObjectRequest request = new JsonObjectRequest(Request.Method.POST, URL", params, future, future); //request contains params with de sql sentence. Its well
VolleyS.getInstance(context).mRequestQueue.add(request);
JSONObject response = future.get(10, TimeUnit.SECONDS); //response contains the wrong error and the database isn't changed
if (response.getInt("success") == 0) correctoExterna = false;
else correctoExterna = true;
更新.php
if (isset($_REQUEST['consulta'])){
$vConsulta= $_REQUEST['consulta'];
$result = mysql_query($vConsulta);
// mysqli_errno($db) != 0
if ($result)
{
$response["success"] = 1;
$response["message"] = "OK.";
echo json_encode($response);
myqli_commit($db);
mysqli_close($db);
}
else{
$response["success"] = 0;
$response["message"] = "ERROR :".mysqli_error($db);
echo json_encode($response);
mysqli_rollback($db);
mysqli_close($db);
}
}
else {
$response["success"] = 0;
$response["message"] = "ERROR, missing fields to insert";
echo json_encode($response);
mysqli_close($db);
}