我已经尝试了很多次来让它工作,但无论我尝试什么都不起作用。我研究了许多教程,但没有找到任何有用的东西。请问有什么建议或帮助吗?!!代码似乎有什么问题吗?
- (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;
}