I am creating a login page through Objective c. When the user types in email and password, those two fields are sent to a php page and processed. If the email and password are correct, the page echoes yes otherwise it echoes no. The problem is that it is echoing Yes, but what is supposed to happen when it echoes Yes does not. Even when I create a NSLog of the received data, it says Yes. Here is my Objective c:
-(void) login{
NSString *post =[NSString stringWithFormat:@"email=%@&pass=%@",email.text, password.text];
NSString *hostStr = @"http://localhost/checkLogin.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 *alertsuccess = [[UIAlertView alloc] initWithTitle:@"" message:@"You are authorized"
delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil];
[alertsuccess show];
} else {
UIAlertView *alertsuccess1 = [[UIAlertView alloc] initWithTitle:@"" message:@"Invalid Access"
delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil];
[alertsuccess1 show];
NSLog(serverOutput);
}
}
-(IBAction)checkLogin:(id)sender{
[self.view endEditing:YES];
[self login];
}
Here is my php:
<?php
$db_connect = mysql_connect("localhost", "root", "")
or die("Our servers are down at the moment");
mysql_select_db("Login Test") or die("Couldnt find db");
$email = $_GET['email'];
$pass = $_GET['pass'];
$query = mysql_query("SELECT * FROM Users WHERE Email='$email'");
$numrows = mysql_num_rows($query);
if($numrows!=0)
{
while ($row = mysql_fetch_assoc($query))
{
$dbemail = $row['Email'];
$dbpassword = $row['Pass'];
}
if ($pass == $dbpassword && $email == $dbemail){
echo "Yes";
}
else{
echo "No";
}
}
mysql_close();
?>