I am trying to make a registration system for the iphone. Everything works fine and the server return the message after it checks if the user already exist. The only problem is that the alert view is not shown when the string returned is equal to this one:
This is the code:
PHP
//other stuff here
//verify if user already in database
$verify = "SELECT userid
FROM user
WHERE userid=:user LIMIT 1;";
$verifyQry = $db_conn->prepare($verify);
$verifyQry->bindParam(':user', $user);
$verifyQry->execute();
$userExists = $verifyQry->fetch();
//if user not in the database, add!
if (!$userExists) {
$insert = 'INSERT INTO user(`userid`,`password`) VALUES (:user,:password)';
$qry = $db_conn->prepare($insert);
$qry->bindParam(':user', $user);
$qry->bindParam(':password', $pass);
$qry->execute();
$message = "success";
}else{
$message = "userExist";
}
echo utf8_encode($message);
XCODE
-(void)signUpWithUsername:(NSString *)username andWithPassword:(NSString *)password{
//NSString *token = [[NSUserDefaults standardUserDefaults]
// objectForKey:@"tokenId"];
dispatch_async(kBgQueue, ^{
NSString *rawStr = [NSString stringWithFormat:@"username=%@&password=%@", username,
password];
NSData *data = [rawStr dataUsingEncoding:NSUTF8StringEncoding];
NSURL *url = [NSURL URLWithString:@"http://www.myserver.com/api/registerUser.php"];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
[request setHTTPMethod:@"POST"];
[request setHTTPBody:data];
NSURLResponse *response;
NSError *err;
NSData *responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&err];
NSString *responseString = [NSString stringWithUTF8String:[responseData bytes]];
NSLog(@"%@", responseString);// I GOT THIS STRING FROM THE SERVER I
if ([responseString isEqualToString: @"userExist"]) {
UIAlertView *userExistAlert = [[UIAlertView alloc]initWithTitle:@"User Exist" message:@"A user with this email address has already sign up. Did you forgot your password" delegate:self cancelButtonTitle:@"cancel" otherButtonTitles:@"retrive password", nil];
[userExistAlert show];
}else{
}
[self dismissViewControllerAnimated:YES completion:nil]; // Dismiss the viewController upon success
});
}