0
I’m trying to connect my Android Java application via php with my MYSQL database and insert data in it, but despite the Android application report 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();
}
} }
php.
/* file code related.php */
$connection = mysqli_connect("localhost", "root", "", "affiliate");
if($_SERVER["REQUEST_METHOD"]="POST") { require 'connection.php'; inseAfiliado(); } Function inserts affiliated() { 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); }