PHP - ¿Como solucionar el problema de guardar un registro en BD android studio?

 
Vista:
Imágen de perfil de Angel
Val: 27
Ha aumentado su posición en 24 puestos en PHP (en relación al último mes)
Gráfica de PHP

¿Como solucionar el problema de guardar un registro en BD android studio?

Publicado por Angel (14 intervenciones) el 19/06/2021 06:10:28
Que tal amigos estoy creando un registro de usuarios de una app en android studio y guardarlos en la base de datos con el gestor MySQL , el cual he venido teniendo un problemas con el servidor local lo tengo con xampp,cuando lleno el registro y doy clic en el botón registrar no sucede nada ni tampoco me manda un error en el Logcat, por ahí leí información que cuando coloco el IP de mi red local después agregue el puerto de mi servidor pero aun así lo intente y no me funciono.

PHP
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
<?php
 
 $con = mysqli_connect("localhost","logishuman","root","");
 
 $nombre = $_POST["nombre"];
 $nombreUsuario = $_POST["nombreUsuario"];
 $email = $_POST["email"];
 $contraseña = $_POST["contraseña"];
 
$statement = mysqli_prepare($con, "INSERT INTO    t_usuario_final(nombre,nombreUsuario,email,contraseña) VALUES
 (?,?,?,?)");
 
 mysqli_stmt_bind_param($statement, "ssss", $nombre, $nombreUsuario, $email, $contraseña);
 mysqli_stmt_execute($statement);
 
$response = array();
$response ["success"] = true;
echo json_encode($response);
 
 ?>


RegistroUser.java

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
public class RegistroUser extends AppCompatActivity {
 
@Override
protected void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 setContentView(R.layout.activity_registro_user);
 getSupportActionBar().setTitle("Formulario de registro");
 
 EditText nombreT = (EditText) findViewById(R.id.texnombre);
 EditText nombreUsuarioT = (EditText) findViewById(R.id.texnombreuser);
 EditText emailT = (EditText) findViewById(R.id.texcorreo);
 EditText contraseñaT = (EditText) findViewById(R.id.texpass);
 Button btnregistrar = (Button) findViewById(R.id.btnregistrar);
 
 btnregistrar.setOnClickListener(new View.OnClickListener() {
     @Override
     public void onClick(View view) {
         String nombre = nombreT.getText().toString();
         String nombreUsuario = nombreUsuarioT.getText().toString();
         String email = emailT.getText().toString();
         String contraseña = contraseñaT.getText().toString();
 
         Response.Listener<String> respuesta = new Response.Listener<String>() {
             @Override
             public void onResponse(String response) {
 
                 try {
                     JSONObject jsonRespuesta = new JSONObject(response);
                     boolean ok = jsonRespuesta.getBoolean("success");
                     if (ok == true) {
                         Intent i = new Intent(RegistroUser.this, LoginActivity.class);
                         RegistroUser.this.startActivity(i);
                         RegistroUser.this.finish();
                     } else {
                         AlertDialog.Builder alerta = new AlertDialog.Builder(RegistroUser.this);
                         alerta.setMessage("El registro a fallado").setNegativeButton("Reintentar de nuevo", null)
                                 .create()
                                 .show();
                     }
                 } catch (JSONException e) {
                     e.getMessage();
                 }
             }
         };
         RegistroRequest r = new RegistroRequest(nombre, nombreUsuario, email, contraseña,  respuesta);
         RequestQueue cola = Volley.newRequestQueue(RegistroUser.this);
         cola.add(r);
     }
 });
 
  }
 }


RegistroRequest.java

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
public class RegistroRequest extends StringRequest {
private static final String ruta = "http://192.168.5.12/LogisticaHumanitaria/registroUserFinal.php";
private Map<String, String> parametros;
public RegistroRequest(String nombre,String nombreUsuario,String email, String contraseña,   Response.Listener<String> listener){
super(Request.Method.POST, ruta, listener,   null);
parametros = new HashMap<>();
parametros.put("nombre",nombre+"");
parametros.put("nombreUsuario",nombreUsuario+"");
parametros.put("email",email+"");
parametros.put("contraseña",contraseña+"");
 }
 
 @Override
  protected Map<String, String> getParams()  {
  return parametros;
  }
}

build.gradle Tengo agregado la siguiente librería
1
implementation 'com.android.volley:volley:1.1.1'

AndroidManifest.xml tengo agregado lo siguiente

1
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder