これを機能させるために何度も試みましたが、何を試しても機能しません。私は多くのチュートリアルを調査しましたが、役に立つものを見つけることができませんでした. ヒントやヘルプをお願いします!! コードに何か問題があるように見えますか?
- (IBAction)login:(id)sender {
NSString *post =[NSString stringWithFormat:@"username=%@&pass=%@",usernameField.text, passwordField.text];
NSString *hostStr = @"http://new-host-3.home/login.php?";
hostStr = [hostStr stringByAppendingString:post];
NSData *dataURL = [NSData dataWithContentsOfURL: [ NSURL URLWithString: hostStr ]];
NSString *serverOutput = [[NSString alloc] initWithData:dataURL encoding: NSASCIIStringEncoding];
if([serverOutput isEqualToString:@"Yes"]){
UIAlertView *alertYes = [[UIAlertView alloc] initWithTitle:@"Succsess!" message:@"You are logged in!" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
[alertYes show];
}
else {
UIAlertView *alertFail = [[UIAlertView alloc] initWithTitle:@"Error" message:@"Username or Password Incorrect"
delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
[alertFail show];
}
}
<?php
session_start();
$con = mysqli_connect("localhost","root","monkeys","lian");
$u = $_GET['username'];
$pw = $_GET['pass'];
$check = "SELECT username,pass FROM members WHERE username='$u' AND pass='$pw'";
$login = mysqli_query($con,$check) or die(mysqli_error($con));
$num_rows = mysqli_num_rows($login);
echo "$num_rows \n";
echo "$u \n";
echo "$pw \n";
if (mysqli_num_rows($login) >= 1) {
$row = mysqli_fetch_assoc($login);
echo 'Yes';
exit;
}
else {
echo ' No';
exit;
}