-1
I have this code to insert data into an external database, but when the save button is clicked, it inserts a new entry into the table, but empty. The php script works well because using Postman correctly inserts the data.
private void insertData() {
textSensorName = findViewById(R.id.eTSensorName);
textDescription = findViewById(R.id.eTDescription);
textAttributes1 = findViewById(R.id.eTAttributes1);
textAttributes2 = findViewById(R.id.eTAttributes2);
textAttributes3 = findViewById(R.id.eTAttributes3);
textAttributes4 = findViewById(R.id.eTAttributes4);
String nome = textSensorName.getText().toString();
String descricao = textDescription.getText().toString();
String s1 = textAttributes1.getText().toString();
String s2 = textAttributes2.getText().toString();
String s3 = textAttributes3.getText().toString();
String s4 = textAttributes4.getText().toString();
StringRequest request = new StringRequest(Request.Method.POST,INSERT_SENSOR_REQUEST, new Response.Listener<String>() {
@Override
public void onResponse(String response) {
Toast.makeText(getApplicationContext(), response.toString(), Toast.LENGTH_LONG).show();
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(getApplicationContext(), error.toString(), Toast.LENGTH_LONG).show();
}
}){
@Override
protected Map<String, String> getParams() throws AuthFailureError {
Map<String, String> param = new HashMap<String, String>();
param.put("nome", nome);
param.put("descricao", descricao);
param.put("s1", s1);
param.put("s2", s2);
param.put("s3", s3);
param.put("s4", s4);
return super.getParams();
}
};
RequestQueue queue = Volley.newRequestQueue(getApplicationContext());
queue.add(request);
}
"The php script works well because using Postman" so the problem is on the application side, have you debugged to see if the data is being sent correctly? then debug php to see if the parameters get tbm correctly there?
– Ricardo Pontual
@Ricardopunctual he never gets to enter this piece of code:
@Override
 protected Map<String, String> getParams() throws AuthFailureError {
 Map<String, String> param = new HashMap<String, String>();
 param.put("nome", nome);
 param.put("descricao", descricao);
 param.put("s1", s1);
 param.put("s2", s2);
 param.put("s3", s3);
 param.put("s4", s4);
 return super.getParams();

– Diogo Simao