Actually i follow many stackoverflow answers related my question but none of answer is working and i simply post a string and in return i want a json Array
NOTE: when i run my Hard code script it's perfectly well but in the script the POST value shows null Here is my Android code:
private void getData(){
Bundle extras=getIntent().getExtras();
final String id = extras.getString("value").toString().trim();
JSONObject obj =new JSONObject();
final ProgressDialog loading = ProgressDialog.show(Categories.this, "Please wait...","Fetching data...",false,false);
Volley.newRequestQueue(this).add(new JsonRequest<JSONArray>(Request.Method.POST, CATEGORIES_URL, obj.toString(),
new Response.Listener<JSONArray>() {
@Override
public void onResponse(JSONArray response) {
loading.dismiss();
showList(response);
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
loading.dismiss();
Toast.makeText(getApplicationContext(),
"Ooops!,Internet Connection Problem", Toast.LENGTH_LONG).show();
}
}) {
@Override
protected Map<String, String> getParams() throws AuthFailureError {
Map<String, String> params = new HashMap<String, String>();
params.put(KEY_ID,id);
return super.getParams();
}
@Override
protected Response<JSONArray> parseNetworkResponse(
NetworkResponse response) {
try {
String jsonString = new String(response.data,
HttpHeaderParser
.parseCharset(response.headers));
return Response.success(new JSONArray(jsonString),
HttpHeaderParser
.parseCacheHeaders(response));
} catch (UnsupportedEncodingException e) {
return Response.error(new ParseError(e));
} catch (JSONException je) {
return Response.error(new ParseError(je));
}
}
});
// RequestQueue requestQueue = Volley.newRequestQueue(this);
// requestQueue.add(jsonArrayRequest);
Toast.makeText(Categories.this,id,Toast.LENGTH_LONG ).show();
}
and on the Server Side i use $id=$_POST['id'];
but it show null
i don't know what's the problem
MY PHP Script :
<?php
require_once('dbConnect.php');
$json = file_get_contents('php://input');
$stripe_json= json_decode($json, TRUE);
$ida=$stripe_json->id;
$sql= "select title,description,image,price,cid FROM products a where a.cid='".$ida."'";
$res=mysqli_query($con,$sql);
$result = array();
while ($row=mysqli_fetch_array($res)){
array_push($result,array('title'=>$row['0'],
'description'=>$row['1'],
'image'=>$row['2'],
'price'=>$row['3'],
));
}
echo json_encode(($result));
mysqli_close($con);
?>