2013-02-16 81 views
1
-(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"]);} 

我想插入用戶信息到服務器端的數據庫,所以我用這一段代碼,它工作正常,但問題是,在我的服務器數據庫中的重複條目像2條記錄一樣插入相同的細節,我無法完全識別問題在我的代碼端或服務器端。請儘快提出一些指導方針。提前致謝!重複插入記錄在服務器數據庫

回答

4

刪除任何一個:

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

或本:

NSData *responseData = [NSURLConnection sendSynchronousRequest:theRequest returningResponse:nil error:nil]; 

即使你有一個要求,你讓兩個不同的連接(其中一個是做一個異步連接,另一個是同步的)。兩者一起等於兩個插入到您的數據庫。

+0

嗨thanx alott !!!它的工作:) – Mak13 2013-02-16 13:45:15

+0

你是偉大的邁克爾.. :)向你致敬.. – 2015-08-05 06:08:53

+0

你是一個救命的人!您的建議幫助我解決了一個奇怪的問題,我試圖通過幾天來解決的通知。謝啦 !! – 2016-06-03 21:03:06