Put this in Login button action
NSString *post = [[NSString alloc] initWithFormat:@"uname=%@&pwd=%@",usernameData,passwordData];
NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]];
NSURL *url = [NSURL URLWithString:@"http://www.yourlink.com/chckLogin.php"];
NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:url];
[theRequest setHTTPMethod:@"POST"];
[theRequest setValue:postLength forHTTPHeaderField:@"Content-Length"];
[theRequest setHTTPBody:postData];
NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
if( theConnection )
{
indicator.hidden = NO;
[indicator startAnimating];
webData = [[NSMutableData data] retain];
}
else
{
NSLog(@"Internet problem maybe...");
}
And then have connection
-(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{
[webData setLength: 0];
}
-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
[webData appendData:data];
}
-(void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
{
// show error
indicator.hidden = YES;
[indicator stopAnimating];
[connection release];
[webData release];
}
-(void)connectionDidFinishLoading:(NSURLConnection *)connection
{
NSString *loginStatus = [[NSString alloc] initWithBytes: [webData mutableBytes] length:[webData length] encoding:NSUTF8StringEncoding];
greetingLabel.text = @"";
NSLog(@"after compareing data is %@", loginStatus);
if ([loginStatus isEqualToString:@"right"]) {
// right login
} else {
// wrong login
greetingLabel.hidden = NO;
greetingLabel.text = @"Incorrect username and/ or password.";
}
[loginStatus release];
[connection release];
[webData release];
indicator.hidden = YES;
}