したがって、データを PHP スクリプトに送信するコードがあります。アイデアは、コードがデータをデータベースに挿入することです。これが成功した場合、返される文字列は「SUCCESSFUL」になり、それ以外の場合は「Failed」になります。成功した値が返されたときに、ありがとう(ラベル)という別のビューをロードする必要があります。どうすればこれを達成できますか?
コード:
(IBAction)saveDataAction:(id)sender {
NSString *lEventTitle = [NSString stringWithFormat:@"var=%@",eventTitle.text];
NSString *lEventDesc = [NSString stringWithFormat:@"var=%@",eventDescription.text];
NSString *lEventCity = [NSString stringWithFormat:@"var=%@",eventCity.text];
// Create your request string with parameter name as defined in PHP file
NSString *myRequestString = [NSString stringWithFormat:@"title=%@&description=%@&city=%@",lEventTitle ,lEventDesc,lEventCity];
myRequestString = [myRequestString stringByReplacingOccurrencesOfString:@"var=" withString:@""];
NSLog(@"%@",myRequestString);
// Create Data from request
NSData *myRequestData = [NSData dataWithBytes: [myRequestString UTF8String] length: [myRequestString length]];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL: [NSURL URLWithString: @"http://www.xsysdevelopment.com/ios/form.php"]];
// set Request Type
[request setHTTPMethod: @"POST"];
// Set content-type
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
// Set Request Body
[request setHTTPBody: myRequestData];
// Now send a request and get Response
NSData *returnData = [NSURLConnection sendSynchronousRequest: request returningResponse: nil error: nil];
// Log Response
NSString *response = [[NSString alloc] initWithBytes:[returnData bytes] length:[returnData length] encoding:NSUTF8StringEncoding];
NSLog(@"%@",response);
if ([response rangeOfString:@"SUCCESSFUL"].location == NSNotFound)
{
//here??
}
}
事前に助けてくれてありがとう