1
I am trying to connect and send a registration, via PHP Nector, from my Android application to SQL Server on the local computer. It’s returning "Error!" because it looks like Volley doesn’t see the Nector, or something like that. Could you help me with what I’m missing?
public class Cadastro extends AppCompatActivity{
EditText txtNome, txtEmail, txtSenha, txtRepeteSenha;
Button btnCadastrar;
ProgressBar progressBar;
ConnectionClass connectionClass;
String url = "http://localhost/cadastro.php";
AlertDialog.Builder alertDialog;
@Override
protected void onCreate (Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_cadastro);
connectionClass = new ConnectionClass();
txtNome = findViewById(R.id.name);
txtEmail = findViewById(R.id.mail);
txtSenha = findViewById(R.id.key);
txtRepeteSenha = findViewById(R.id.key_again);
btnCadastrar = findViewById(R.id.cadastrar);
progressBar = findViewById(R.id.progressBar);
btnCadastrar.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final String nome, email, senha;
nome = txtNome.getText().toString();
email = txtEmail.getText().toString();
senha = txtSenha.getText().toString();
RequestQueue queue = Volley.newRequestQueue(Cadastro.this);
StringRequest stringRequest = new StringRequest(Request.Method.POST, url, new Response.Listener<String>() {
@Override
public void onResponse(String response) {
alertDialog = new AlertDialog.Builder(Cadastro.this);
alertDialog.setTitle("Resposta do servidor:");
alertDialog.setMessage("Resposta: " + response);
alertDialog.setPositiveButton("OK", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
txtNome.setText("");
txtEmail.setText("");
txtSenha.setText("");
}
});
AlertDialog alertDialog2 = alertDialog.create();
alertDialog2.show();
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(Cadastro.this, "Erro!", Toast.LENGTH_SHORT).show();
error.printStackTrace();
}
}){
@Override
protected Map<String, String> getParams() {
Map<String, String> params = new HashMap<>();
params.put("nome", nome);
params.put("email", email);
params.put("senha", senha);
return params;
}
};
queue.add(stringRequest);
}
});
}
Hello Paul, this does not answer your question. You wrote in a place of answers. I advise you to create a new question about the specific problem that is the insertion.
– Andrei Coelho
Your question refers to the connection problem between android and php.
– Andrei Coelho
ok. Leave it to me, create a new post here. Thank you so far.
– Paulo Lara