I want to post some data to a url, then get the posted data from that url and store it in a database. I've tried to echo the posted params but they appear not to have been posted and no error is shown. Below is the function I use to do the post:
public void insertDataWithVolley() {
String url = "http://apps.example.com/application/index.php/main/getParamsFromVolley";
RequestQueue requestQueue = Volley.newRequestQueue(this);
StringRequest stringRequest = new StringRequest(Request.Method.POST, url, new Response.Listener<String>() {
@Override
public void onResponse(String response) {
Toast.makeText(getApplicationContext(), response,
Toast.LENGTH_LONG).show();
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(getApplicationContext(), error.getMessage(),
Toast.LENGTH_LONG).show();
}
}) {
protected Map<String, String> getParams() throws AuthFailureError {
Map<String, String> mapObject = new HashMap<>();
mapObject.put("id", "ID");
Log.d("TAG", "Put id");
mapObject.put("name", "NAME");
Log.d("TAG", "Put name");
return mapObject;
}
};
requestQueue.add(stringRequest);
}
On the PHP side, this is the function, see below:
public function getParamsFromVolley() {
$id = null;
$name = null;
if (isset($_GET['id'])) {
$id= $this->input->get('id');
}
if (isset($_GET['name'])) {
$name= $this->input->get('name');
}
//store $pesapal_tracking_id in your database against the order with orderid = $reference09
echo 'name>>>>' . $id;
echo 'email>>>>' . $name;
//return $pesapal_tracking_id;
}
Kindly assist