1

Hello everyone I am trying to insert my user data in myaql database using JSON. But i am unable to do so, data is not inserting and getting no error. following is my code.

Objective C Code

    {
     NSString *post =[NSString stringWithFormat:@"name=%@&email=%@&password=  %@&phone=%@",self.name.text, self.Pass.text,self.phone.text,self.email.text];
     NSData *data = [post dataUsingEncoding:NSUTF8StringEncoding];
     NSURL *url = [NSURL URLWithString:@"http://my url"];
     NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
     [request setHTTPMethod:@"POST"];
     [request setHTTPBody:data];
     NSURLResponse *response;
     NSError *err;
     NSData *responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&err];
    NSLog(@"responseData: %@", responseData);
    }

I am using this code to insert textfields data into my mysql database.It seems no error but data is not inserting in my database. Thanks in Advance.

2
  • there is a space after password= ?? and what print NSLog? Commented Nov 27, 2014 at 12:26
  • NSLog print response data Commented Nov 27, 2014 at 12:30

2 Answers 2

3

Your first line itself doesn't seem true:

NSString *post =[NSString stringWithFormat:@"name=%@&email=%@&password=  %@&phone=%@",

self.name.text, self.Pass.text,self.phone.text,self.email.text];
  1. Do you require space " " after text "password="
  2. In formation the sequence is: name, email, password, phone, but in parameter list phone is at third place and email at last.

It should be:

NSString *post =[NSString stringWithFormat:@"name=%@&email=%@&password=%@&phone=%@",

self.name.text, self.email.text,self.Pass.text,self.phone.text];

I guess that's causing issue, it might be in datatype mismatch with database table schema, for phone column (numbers) to email column (characters).

Sign up to request clarification or add additional context in comments.

Comments

1

Seems like your iOS implementation is correct, but your server side is not. You could try the following: In your Server-side script, where your MySQL insert-statement is being generated, just do a

echo $insertScript;

and then run your App again and see what the response says. It should return a valid MySQL insert script. Copy it and run it on your server's mysql instance and see what happens

Also, remove those spaces in your password field

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.