0

I'm trying to add data to a remote MySQL database and it works perfect until I add a SPACE to my text fill in order to write the second word. Can someone help me out with this? Here's the code

- (IBAction)add:(id)sender {
    NSString *strURL = [NSString stringWithFormat:@"http://pruebapestana.comoj.com/juancho4.php?name=%@&last=%@&age=%@",_name.text, _last.text, _age.text];
1
  • You don't add data to a remote DB from Xcode. You can do so from your iOS app or OS X program, but not Xcode. Commented Jun 29, 2013 at 22:55

1 Answer 1

1

Spaces are not valid characters in a URL. You need to properly escape them so they become %20. The best way to do this is to use the NSString method stringByAddingPercentEscapesUsingEncoding:.

NSString *strURL = [NSString stringWithFormat:@"http://pruebapestana.comoj.com/juancho4.php?name=%@&last=%@&age=%@",
    [_name.text stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding], 
    [_last.text stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding], 
    [_age.text stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];

This will properly escape any other special values in addition to the spaces.

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

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.