我的代码工作正常,我得到了我需要的所有信息,但是我必须从用户那里写下我想要的信息在我的php文件中。我想从用户那里获得我在文本字段中写下他的电子邮件的信息。我怎么能这样做?
这是我的php文件:
<?php
$servername = "*****";
$username = "*****";
$password = "*****";
$dbname = "*****";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
//I want to get this email information from my xcode text field
$sql = "SELECT id, nome, email, cpf, senha FROM usuario_log where email = 'albino@peggou.com.br'";
$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();
?>
这是我的.m文件,所有信息都显示在我的日志中。
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);