Android Studio: insert data into a Mysql BD

Asked

Viewed 18 times

-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?

  • @Ricardopunctual he never gets to enter this piece of code: @Override&#xA; protected Map<String, String> getParams() throws AuthFailureError {&#xA; Map<String, String> param = new HashMap<String, String>();&#xA; param.put("nome", nome);&#xA; param.put("descricao", descricao);&#xA; param.put("s1", s1);&#xA; param.put("s2", s2);&#xA; param.put("s3", s3);&#xA; param.put("s4", s4);&#xA; return super.getParams();&#xA;

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.