Here's my Android code that first picks phone from another class:
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
int defaultValue = 0;
phone = prefs.getString("Number", String.valueOf(defaultValue));
then trying to post it by volley like this:
private void getStatus(final String phone) {
final String URL = Config.DATA_URL_STATUS;
// Post params to be sent to the server
HashMap<String, String> params = new HashMap<String, String>();
params.put("phone",phone);
loading = ProgressDialog.show(this, "Please wait...", "Validating...", false, false);
JsonObjectRequest req = new JsonObjectRequest(URL, new JSONObject(params),
new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
try {
VolleyLog.v("Response:%n %s", response.toString(4));
showJSONE(response);
loading.hide();
} catch (JSONException e) {
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
VolleyLog.e("Error: ", error.getMessage());
loading.hide();
}
});
// add the request object to the queue to be executed
AppController.getInstance().addToRequestQueue(req);
}
My php code:
$con = mysqli_connect(HOST,USER,PASS,DB);
$phone = $_POST['phone'];
$sql = "SELECT * FROM transactions ";
$sql .= "WHERE sender_phone='$phone'";
$sql .= "ORDER BY id DESC LIMIT 1";
The problem is that this code doesn't pick the value for $phone