Iphone 在ios中使用POST请求在服务器数据库中插入重复记录

Iphone 在ios中使用POST请求在服务器数据库中插入重复记录,iphone,ios6,ios5,Iphone,Ios6,Ios5,我想在服务器端数据库中插入用户详细信息,所以我使用了这段代码,它工作得很好,但问题是在我的服务器数据库中插入了重复条目,就像插入了两条具有相同详细信息的记录一样。我无法准确地识别代码端或服务器端的问题所在。请尽快提出一些指导方针。提前谢谢 删除以下任一项: -(void) registerintoserverDB{ NSString *str_registerURL = @"reg_action.php"; NSString *str_completeURL = [NSString strin

我想在服务器端数据库中插入用户详细信息,所以我使用了这段代码,它工作得很好,但问题是在我的服务器数据库中插入了重复条目,就像插入了两条具有相同详细信息的记录一样。我无法准确地识别代码端或服务器端的问题所在。请尽快提出一些指导方针。提前谢谢

删除以下任一项:

-(void) registerintoserverDB{
NSString *str_registerURL = @"reg_action.php";

NSString *str_completeURL = [NSString stringWithFormat:@"%@%@", str_global_domain, str_registerURL]; 

NSURL *url = [NSURL URLWithString:str_completeURL];  

NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:url cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:60];

[theRequest setHTTPMethod:@"POST"];
[theRequest setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"]; 

NSString *str_address = [NSString stringWithFormat:@"%@%@", txt_address1.text, txt_address2.text];   

NSString *postData = [NSString stringWithFormat:@"rest_name=%@&rest_telephone=%@&rest_email=%@&rest_password=%@&rest_country=%@&rest_city=%@&rest_postal=%@&rest_delivery=%@&rest_address=%@&rest_image=%@&rest_minimum_order=%@&isUser=%@&fb_name=%@fb_like", txt_restaurantname.text, txt_telephone.text, txt_email.text, txt_pass.text, txt_country.text, txt_city.text, txt_postal.text, txt_deliveryHours.text,  str_address, @"imagepath", @"10 euro", @"Yes", str_global_user_fbUsername];  

NSString *length = [NSString stringWithFormat:@"%d", [postData length]];
[theRequest setValue:length forHTTPHeaderField:@"Content-Length"]; 

[theRequest setHTTPBody:[postData dataUsingEncoding:NSASCIIStringEncoding]];  

NSURLConnection *sConnection = [NSURLConnection connectionWithRequest:theRequest delegate:self];
[sConnection start];   

NSData *responseData = [NSURLConnection sendSynchronousRequest:theRequest returningResponse:nil error:nil];
NSLog(@"response data is %@", responseData);  

NSString *returnString = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];

NSLog(@"returnString....%@",returnString);
NSDictionary *response_dic = [NSJSONSerialization JSONObjectWithData:responseData options:kNilOptions error:nil];

NSLog(@"msg is  : %@ ",[response_dic objectForKey:@"msg"]);}
或者这个:

NSURLConnection *sConnection = [NSURLConnection connectionWithRequest:theRequest delegate:self];
[sConnection start];   
即使您有一个请求,您也在进行两个不同的连接(一个是异步连接,另一个是同步连接)。两者加在一起等于对数据库的两次插入。

删除以下任一项:

-(void) registerintoserverDB{
NSString *str_registerURL = @"reg_action.php";

NSString *str_completeURL = [NSString stringWithFormat:@"%@%@", str_global_domain, str_registerURL]; 

NSURL *url = [NSURL URLWithString:str_completeURL];  

NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:url cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:60];

[theRequest setHTTPMethod:@"POST"];
[theRequest setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"]; 

NSString *str_address = [NSString stringWithFormat:@"%@%@", txt_address1.text, txt_address2.text];   

NSString *postData = [NSString stringWithFormat:@"rest_name=%@&rest_telephone=%@&rest_email=%@&rest_password=%@&rest_country=%@&rest_city=%@&rest_postal=%@&rest_delivery=%@&rest_address=%@&rest_image=%@&rest_minimum_order=%@&isUser=%@&fb_name=%@fb_like", txt_restaurantname.text, txt_telephone.text, txt_email.text, txt_pass.text, txt_country.text, txt_city.text, txt_postal.text, txt_deliveryHours.text,  str_address, @"imagepath", @"10 euro", @"Yes", str_global_user_fbUsername];  

NSString *length = [NSString stringWithFormat:@"%d", [postData length]];
[theRequest setValue:length forHTTPHeaderField:@"Content-Length"]; 

[theRequest setHTTPBody:[postData dataUsingEncoding:NSASCIIStringEncoding]];  

NSURLConnection *sConnection = [NSURLConnection connectionWithRequest:theRequest delegate:self];
[sConnection start];   

NSData *responseData = [NSURLConnection sendSynchronousRequest:theRequest returningResponse:nil error:nil];
NSLog(@"response data is %@", responseData);  

NSString *returnString = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];

NSLog(@"returnString....%@",returnString);
NSDictionary *response_dic = [NSJSONSerialization JSONObjectWithData:responseData options:kNilOptions error:nil];

NSLog(@"msg is  : %@ ",[response_dic objectForKey:@"msg"]);}
或者这个:

NSURLConnection *sConnection = [NSURLConnection connectionWithRequest:theRequest delegate:self];
[sConnection start];   

即使您有一个请求,您也在进行两个不同的连接(一个是异步连接,另一个是同步连接)。两者加在一起等于两次插入数据库。

你是一个救生员!!你的建议帮助我修复了一个奇怪的问题,我从几天前就开始尝试修复通知。谢谢你!!你是个救命的人!!你的建议帮助我修复了一个奇怪的问题,我从几天前就开始尝试修复通知。谢谢你!!