Reputation: 3
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];
Upvotes: 0
Views: 57
Reputation: 318934
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.
Upvotes: 1