2014-01-08 42 views
-2

編碼:我的代碼有錯誤,我該如何解決?我貼我的編碼和控制檯部分

-(IBAction)regist:(id)sender 
{ 

NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:@"http://www.alvinchuastudios.com/aNSWERED/insert_user.php"]]; 
// create the Method "GET" or "POST" 

[request setHTTPMethod:@"POST"]; 


NSLog(@"the email is:%@",txtemail.text); 
NSLog(@"the login is:%@",txtuser1.text); 
NSLog(@"the pass is:%@",txtpass1.text); 
NSLog(@"the last update by person is:%@",txtuser1.text); 
NSLog(@"the user registered is:%@",datestr); 
//Pass The String to server 
    NSString *userUpdate =[NSString stringWithFormat:@"user_email=%@&@user_login=%@&@user_pass=%@&@last_upd_by=%@&user_registered=%@&",txtemail.text,txtuser1.text,txtpass1.text,txtuser1.text,datestr,nil]; 
    //NSString *userUpdate =[NSString stringWithFormat:@"user_email=gokul&@user_login=shyam&@user_pass=vaishak&@last_upd_by=shiva&user_registered=2014-01-07 16:18:43&",nil]; 
//Check The Value what we passed 
NSLog(@"the data Details is =%@", userUpdate); 

//Convert the String to Data 
NSData *data1 = [userUpdate dataUsingEncoding:NSUTF8StringEncoding]; 

//Apply the data to the body 
[request setHTTPBody:data1]; 

//Create the response and Error 

NSError *err; 
NSURLResponse *response; 

NSData *responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&err]; 

NSString *resSrt = [[NSString alloc]initWithData:responseData encoding:NSASCIIStringEncoding]; 

//This is for Response 
NSLog(@"got response==%@", resSrt); 

if(resSrt) 
{ 
    NSLog(@"got response"); 
    /* ViewController *view =[[ViewController alloc]initWithNibName:@"ViewController" bundle:NULL]; 

    [self presentViewController:view animated:YES completion:nil];*/ 



} 
else 
{ 
    NSLog(@"faield to connect"); 
} 



//ViewController *view =[[ViewController alloc]initWithNibName:@"ViewController" bundle:NULL]; 

//[self presentViewController:view animated:YES completion:nil]; 

[self.navigationController popToRootViewControllerAnimated:YES]; 


} 

CONSOLE聲明:

the email is:[email protected] 
the login is:ShyamSundar 
the pass is:itdone 
the last update by person is:ShyamSundar 
the user registered is:2014-01-08 11:28:40 
the data Details is [email protected]&@user_login=ShyamSundar&@user_pass=itdone&@last_upd_by=ShyamSundar&user_registered=2014-01-08 11:28:40& 
got response==Value1 : [email protected], Value2: , Value3: , Value4: , Value5: 2014-01-08 11:28:40{"success":0,"message":"Required Fields are missing!"} 
got response 
+2

OK我想對於初學者來說,史蒂夫,請告訴我們什麼你的問題是,而不是隻是「與下面的代碼錯誤」 – logixologist

+0

任何人都可以找到插入所需的數據字段? – SteveGokul

+0

只需添加一些你想要的描述 – iPrabu

回答

0

只需更換這種編碼

-(IBAction)regist:(id)sender 
{ 

NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:@"http://www.alvinchuastudios.com/aNSWERED/insert_user.php"]]; 
// create the Method "GET" or "POST" 

[request setHTTPMethod:@"POST"]; 



//Pass The String to server 
NSString *userUpdate =[NSString stringWithFormat:@"user_email=%@&user_login=%@&user_pass=%@& last_upd_by=%@&user_registered=%@&",txtemail.text,txtuser1.text,txtpass1.text,txtuser1.text,datestr,nil]; 
//NSString *userUpdate =[NSString stringWithFormat:@"user_email=gokul&@user_login=shyam&@user_pass=vaishak&@last_upd_by=shiva&user_registered=2014-01-07 16:18:43&",nil]; 
//Check The Value what we passed 
NSLog(@"the data Details is =%@", userUpdate); 

//Convert the String to Data 
NSData *data1 = [userUpdate dataUsingEncoding:NSUTF8StringEncoding]; 

//Apply the data to the body 
[request setHTTPBody:data1]; 

//Create the response and Error 

NSError *err; 
NSURLResponse *response; 

NSData *responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&err]; 

NSString *resSrt = [[NSString alloc]initWithData:responseData encoding:NSASCIIStringEncoding]; 

//This is for Response 
NSLog(@"got response==%@", resSrt); 

if(resSrt) 
{ 
NSLog(@"got response"); 
/* ViewController *view =[[ViewController alloc]initWithNibName:@"ViewController" bundle:NULL]; 

    [self presentViewController:view animated:YES completion:nil];*/ 



} 
else 
{ 
NSLog(@"faield to connect"); 
} 
+0

非常感謝我的朋友 –

相關問題