我的以下代码有错误。我该如何解决?我发布了我的编码和控制台部分[关闭]

Posted

技术标签:

【中文标题】我的以下代码有错误。我该如何解决?我发布了我的编码和控制台部分[关闭]【英文标题】:I have an error with my following code.How can i solve that? i posted my coding and console part [closed] 【发布时间】:2014-01-08 07:10:15 【问题描述】:

编码:

-(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];



控制台声明:

the email is:shyam1303@gmail.com
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 =user_email=shyam1303@gmail.com&@user_login=ShyamSundar&@user_pass=itdone&@last_upd_by=ShyamSundar&user_registered=2014-01-08 11:28:40&
got response==Value1 : shyam1303@gmail.com, Value2: , Value3: , Value4: , Value5: 2014-01-08 11:28:40"success":0,"message":"Required Fields are missing!"
got response

【问题讨论】:

好的,我想首先,史蒂夫,请告诉我们您的问题是什么,而不仅仅是“以下代码出错” 有谁知道插入数据的必填字段吗? 只需添加一些你想要的描述 是的。问题是我想通过 json post 插入服务器中的所有值。我通过上面的代码做到了。但它显示我缺少必填字段。我给了所有字段 coorectly . 我想在服务器中添加缺少的字段。 【参考方案1】:

只需替换此编码

-(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");

【讨论】:

非常感谢我的朋友

以上是关于我的以下代码有错误。我该如何解决?我发布了我的编码和控制台部分[关闭]的主要内容,如果未能解决你的问题,请参考以下文章

类型错误,我该如何解决这个错误,在图片中我写了我的具体问题

Python 3 无法读取我的 .txt 文件。我该如何解决? [复制]

更改了我的包裹名称,现在我的谷歌地图显示为白屏,我该如何解决这个问题?

双向链表 - 是啥导致我的代码引发编译器错误,我该如何解决?

如果我的测试数据在列中缺少值,我该如何解决一个热编码?

我该如何解决这个错误无法打开 SSL LIbrary