MYSQL connection error on Android using php

0

I'm trying to connect my Android Java application via php with my MYSQL database and insert data into it, but despite the Android application reporting that the "user was successfully registered" the data I try to insert does not appear in the database.

I'm using the following codes:

Android Java

public class MainActivity extends AppCompatActivity {
    private EditText email, senha, cpf, telefone, membroDesde, nome, pontos;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    email = (EditText) findViewById(R.id.email);
    senha = (EditText) findViewById(R.id.senha);
    cpf = (EditText) findViewById(R.id.cpf);
    telefone = (EditText) findViewById(R.id.telefone);
    membroDesde = (EditText) findViewById(R.id.membroDesde);
    nome = (EditText) findViewById(R.id.nome);
    pontos = (EditText) findViewById(R.id.pontos);
}

public void cadastrar(View view) {
    String emailLogin = email.getText().toString();
    String senhaLogin = senha.getText().toString();
    String cpfLogin = cpf.getText().toString();
    String telefoneLogin = telefone.getText().toString();
    String membroDesdeLogin = membroDesde.getText().toString();
    String nomeLogin = nome.getText().toString();
    String pontosLogin = pontos.getText().toString();

    if (!(emailLogin.isEmpty()) && !(senhaLogin.isEmpty())) {
        Ion.with(MainActivity.this)
                .load("http://192.168.15.12/conexaoBanco/cadastro.php")
                .setBodyParameter("emailLogin", emailLogin)
                .setBodyParameter("cpfLogin", cpfLogin)
                .setBodyParameter("senhaLogin", senhaLogin)
                .setBodyParameter("telefoneLogin", telefoneLogin)
                .setBodyParameter("nomeLogin", nomeLogin)
                .setBodyParameter("membroDesdeLogin", membroDesdeLogin)
                .setBodyParameter("pontosLogin", pontosLogin)
                .asJsonObject()
                .setCallback(new FutureCallback<JsonObject>() {
                    @Override
                    public void onCompleted(Exception e, JsonObject result) {
                        try {
                            Toast.makeText(MainActivity.this, R.string.sucessoCadastro, Toast.LENGTH_LONG).show();
                        } catch (Exception error) {
                            Toast.makeText(MainActivity.this, R.string.errorCadastro, Toast.LENGTH_LONG).show();
                        }
                    }
                });
    } else {
        Toast.makeText(MainActivity.this, "Todos os campos precisam ser preenchidos", Toast.LENGTH_LONG).show();
    }
} }

cadastro.php

/ * file code connection.php * /

$ connection = mysqli_connect ("localhost", "root", "", "affiliate");

if ($ _ SERVER ["REQUEST_METHOD"] == "POST") {     require 'connection.php';     insertAssign (); }     function insertAssign ()     {          global $ connect;

     $nome = $_POST["nomeLogin"];
     $email = $_POST["emailLogin"];
     $cpf = $_POST["cpfLogin"];
     $senha = $_POST["senhaLogin"];
     $pontos = $_POST["pontosLogin"];
     $telefone = $_POST["telefoneLogin"];
     $membroDesde = $_POST["membroDesdeLogin"];

$query = "INSERT into afiliado (nome, cpf, pontos, telefone, email, senha, membro_desde) values ('$nome', '$cpf', '$pontos', '$telefone', '$email', '$senha', '$membro_desde')";


 mysqli_query($connect, $query) OR DIE(mysql_error($connect));
     var_dump(mysqli_query);
     mysqli_close($connect);  }
    
asked by anonymous 10.12.2018 / 13:28

1 answer

0

The error occurred first, because the database only accepted the data as varchar , even some fields being of other types, and later on account of the Windows firewall that was locking the xampp server port.

    
10.12.2018 / 17:43