Help, I need to insert a value that comes from a putextra, adroid studio and mysql

0

// THIS IS MY ACTIVITY FROM INSERTING USER

The value is an extra put, loguser, it shows me the value on the screen but it does not register it in the database.

 protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_add_usuario);

    logusuario=(EditText) findViewById(R.id.etingresadopor);
    Intent intmostrar= getIntent();
    mostrardelogin=intmostrar.getExtras().getString("UsuarioMostrar");
    logusuario.setText(mostrardelogin);


    et1 = (EditText) findViewById(R.id.codeAddUser);
    et2 = (EditText) findViewById(R.id.etusaurioAddUser);
    et3 = (EditText) findViewById(R.id.etpassAddUser);
    btnAddUser = (Button) findViewById(R.id.btnAddUser);
    btnSalir = (Button) findViewById(R.id.btnExit);
    btnAddUser.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            submitForm();
            et1.requestFocus();
            Limpiar();
        }
    });

}

// *****************************

        private void submitForm() {
        InsertarUser(et1.getText().toString(),
            et2.getText().toString(),
            et3.getText().toString(),
            muestraUser.getSelectedItem().toString(),
            logusuario.getText().toString()
            );
       }

     private void InsertarUser(final String Code,  final String User, 
    final String Pass,final String TipoUsuario,final String Usuario_ingreso) {
    // Tag used to cancel the request
    String cancel_req_tag = "register";
    showLoadingDialog("Espere  insertando  datos ....");

    StringRequest strReq = new StringRequest(Request.Method.POST,
            Config.URL_ADD_USER, new Response.Listener<String>() {

        @Override
        public void onResponse(String response) {
            Log.d(TAG, "Register Response: " + response.toString());

            try {
                hideLoadingDialog();
                JSONObject jObj = new JSONObject(response);
                String estado = jObj.getString("estado");

                if (estado.equalsIgnoreCase("1")) {
                      Toast toast1= 
         Toast.makeText(addUsuario.this,"Inserción  correcta",Toast.LENGTH_LONG);
                    toast1.setGravity(Gravity.CENTER|Gravity.CENTER,0,0);
                    toast1.show();
                } else {
                    hideLoadingDialog();

                    Toast toast2= Toast.makeText(getApplicationContext(), "No se realizó la inserción  por que ya existe un Usuario con este código", Toast.LENGTH_LONG);
                    toast2.setGravity(Gravity.CENTER|Gravity.CENTER,0,0);
                    toast2.show();
                }
            } catch (JSONException e) {
                e.printStackTrace();
            }

        }
    }, new Response.ErrorListener() {

        @Override
        public void onErrorResponse(VolleyError error) {
            Log.e(TAG, "Error al registrar: " + error.getMessage());
            Toast.makeText(getApplicationContext(),
                    error.getMessage(), Toast.LENGTH_LONG).show();
            hideLoadingDialog();
        }
    }) {
        @Override
        protected Map<String, String> getParams() {
            // Posting params to register url
            Map<String, String> params = new HashMap<String, String>();
            params.put("Code",Code);
            params.put("User", User);
            params.put("Pass",Pass);
            params.put("TipoUsuario", TipoUsuario);
            params.put("Usurio_ingreso",Usuario_ingreso);
            return params;
        }
    };
    // Adding request to request queue
    AppSingleton.getInstance(getApplicationContext()).addToRequestQueue(strReq, cancel_req_tag);
}



     public void showLoadingDialog(String texto) {
    try {
        if (progressDialog == null) {
            progressDialog = new ProgressDialog(this);
        }
        progressDialog.setIndeterminate(true);
        progressDialog.setCancelable(false);
        progressDialog.setMessage(texto);
        progressDialog.show();
    } catch (Exception exception) {
        progressDialog = null;
    }

}
    
asked by Sofia 25.05.2017 в 23:47
source

1 answer

0

Thank you for adding the way you send it, analyzing your code, the sending and the way to show it in the EditText loguser and then send it to the InsertarUser() method is correct, the problem seems to be in the HashMap that you create to insert the data.

 @Override
    protected Map<String, String> getParams() {
        // Posting params to register url
        Map<String, String> params = new HashMap<String, String>();
        params.put("Code",Code);
        params.put("User", User);
        params.put("Pass",Pass);
        params.put("TipoUsuario", TipoUsuario);
        params.put("Usurio_ingreso",Usuario_ingreso); //*** Problema.
        return params;
    }

the name of the parameter must surely be "User_incoming".

    
answered by 26.05.2017 в 21:02