Не удалось отправить параметр в PHP POST параметр Android
В настоящее время я использую Android Volley и пытаюсь выбрать сведения о продукте, отправив productID, чтобы получить подробные данные о продукте.
JSONObject params = new JSONObject();
try {
params.put("ProductID", intent.getStringExtra("productID"));
} catch (JSONException e) {
e.printStackTrace();
}
JsonObjectRequest detailReq = new JsonObjectRequest(Request.Method.POST, url, params, new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
txtNama.setText(intent.getStringExtra("nama"));
txtManufacturer.setText(intent.getStringExtra("namaVendor"));
txtHarga.setText("Rp. " + intent.getStringExtra("harga"));
try {
if(!response.getString("Foto1").equals(""))
fotoUrl.add(response.getString("Foto1"));
if(!response.getString("Foto2").equals(""))
fotoUrl.add(response.getString("Foto2"));
if(!response.getString("Foto3").equals(""))
fotoUrl.add(response.getString("Foto3"));
if(!response.getString("Foto4").equals(""))
fotoUrl.add(response.getString("Foto4"));
if(!response.getString("Foto5").equals(""))
fotoUrl.add(response.getString("Foto5"));
txtDesc.setText(response.getString("Deskripsi"));
} catch (JSONException e) {
e.printStackTrace();
}
imageFragmentPagerAdapter.notifyDataSetChanged();
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(ProductActivity.this, "Error occurred! Please check your internet connection!", Toast.LENGTH_LONG).show();
}
});
AppController.getInstance().addToRequestQueue(detailReq);
Но метод onErrorResponse всегда вызывается. Это мой PHP-код:
<?php
require("config.inc.php");
$query = "SELECT Foto1, Foto2, Foto3, Foto4, Foto5, Deskripsi
FROM `product` WHERE `ProductID` = '". $_POST['ProductID']."'";
try {
$stmt = $db->prepare($query);
$result = $stmt->execute();
}
catch (PDOException $ex) {
die(json_encode($response));
}
$row = $stmt->fetch();
if ($row) {
echo json_encode($row);
}
?>
Но когда я изменяю значение $ _POST ['ProductID'], например, на '0001', php работает просто отлично. Любая идея? Заранее спасибо.