i am trying to get volley to work with a php script, to basically submit some data via volley to the php then select from database and return result, however i am struggling to even get the variables from android to submit to the php. The errors i am getting signal that the variables are null when the php is run, so they are not getting submitted properly Here is the php error
PHP Notice: Undefined index: name
And when i try to return the variable name
it returns as null
Here is the php
$iName = $_POST['name'];
$iEmail = $_POST['email'];
$iPassword = $_POST['password'];
$iVerifyPassword = $_POST['verify_password'];
$response = array('code' => "1", 'message' => $iName);
echo json_encode($response);
exit;
Here is the relevant android
HashMap<String, String> params = new HashMap<String, String>();
params.put("name", sName);
params.put("email", sEmail);
params.put("password", sPassword);
params.put("verify_password", sVerifyPassword);
JsonObjectRequest req = new JsonObjectRequest(
jsonUrl, new JSONObject(params),
new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
try {
VolleyLog.v("Response:%n %s", response.toString(4));
int code = response.getInt("code");
String message = response.getString("message");
if (code == 1) {
//Success go to verify
Toast.makeText(getActivity().getApplicationContext(),
message,
Toast.LENGTH_LONG).show();
} else if (code == 2) {
Toast.makeText(getActivity().getApplicationContext(),
message,
Toast.LENGTH_LONG).show();
} else {
Toast.makeText(getActivity().getApplicationContext(),
"Network Error",
Toast.LENGTH_LONG).show();
}
} catch (JSONException e) {
e.printStackTrace();
}
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
VolleyLog.e("Error: ", error.getMessage());
}
}
);
// add the request object to the queue to be executed
AppController.getInstance().addToRequestQueue(req, tag_json_obj);