My code is working, I'm getting the data I need, but I have to write the email of the user who wants the data in my php file. I wanted to receive the user data that the email is typed into a textField in my project. How could I do that?
My php file:
<?php
$servername = "*****";
$username = "*****";
$password = "*****";
$dbname = "*****";
// Criar conexao
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
//Queria pegar os dados do email que escrevi no textField, e para funcionar tenho que escrever o email diretamente no código
$sql = "SELECT id, nome, email, cpf, senha FROM usuario_log where email = '[email protected]'";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
$resultado = array("status" => "0", "id" => $row["id"], "nome" => $row["nome"], "email" => $row["email"], "cpf" => $row["cpf"], "senha" => $row["senha"]);
}
} else {
echo "0 results";
}
echo json_encode($resultado);
$conn->close();
?>
My .m file, I get the data in my Log.
NSString *urlString = [NSString stringWithFormat: @"http://peggou.com.br/dados.php"];
NSURL *url = [NSURL URLWithString:urlString];
NSData *data = [NSData dataWithContentsOfURL:url];
NSDictionary *json = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:nil];
NSString *statusUser = [json objectForKey:@"status"];
NSString *idUser = [json objectForKey:@"id"];
NSString *nomeUser = [json objectForKey:@"nome"];
NSString *emailUser = [json objectForKey:@"email"];
NSString *cpfUser = [json objectForKey:@"cpf"];
NSString *senhaUser = [json objectForKey:@"senha"];
NSLog(@"\n Status: %@,\n ID: %@,\n Nome: %@,\n E-mail: %@,\n CPF: %@,\n Senha: %@ \n", statusUser, idUser, nomeUser, emailUser, cpfUser, senhaUser);