当字符串包含空格时应用程序不会更新数据库

发布于 2025-01-03 20:32:42 字数 613 浏览 2 评论 0原文

我遇到了一个奇怪的问题。我建立了一个 mysql 数据库,用户可以通过应用程序存储他的联系人。他只需点击一个按钮即可添加他的联系信息。然后,数据被添加到数据库中。

但是,当联系人信息的名字、姓氏或号码之间有空格时,应用程序将拒绝接受该数据。我没有收到错误消息或类似的信息,但也没有得到任何确认。该记录在数据库中不存在。

我的php文件没有问题(该文件绝对正确,我在这里检查了两次)。 这是我的代码:

NSString *strURL = [NSString stringWithFormat:@"http://www.abc.com/phpFile.php?number=%@&name=%@&lastname=%@", number, firstName, lastName];

NSData *dataURL = [NSData dataWithContentsOfURL:[NSURL URLWithString:strURL]];
        NSString *strResult = [[NSString alloc] initWithData:dataURL encoding:NSUTF8StringEncoding];

        NSLog(@"%@", strResult);

I ran into a weird problem. I built a mysql database where the user can store his contacts through an app. He just adds his contact information by clicking on a button. Then, the data is added to the database.

However, when the contact's information has spaces between his first name, last name or number the app refuses to accept the data. I dont get an error message or anything like that, but I also dont get any confirmation. The record does not exist in the database.

There is no problem with my php file (The file is definitely correct, I got it checked here, twice).
Here is my code:

NSString *strURL = [NSString stringWithFormat:@"http://www.abc.com/phpFile.php?number=%@&name=%@&lastname=%@", number, firstName, lastName];

NSData *dataURL = [NSData dataWithContentsOfURL:[NSURL URLWithString:strURL]];
        NSString *strResult = [[NSString alloc] initWithData:dataURL encoding:NSUTF8StringEncoding];

        NSLog(@"%@", strResult);

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

望笑 2025-01-10 20:32:42

URI 中不允许使用空格字符。使用 %20 对空格进行编码。还有其他字符也不允许作为 URI 的一部分。查找 URI 编码。

The space character is not allowed in a URI. Use %20 to encode the space. There are other characters that are also not allowed as part of the URI. Look up URI encoding.

难以启齿的温柔 2025-01-10 20:32:42
NSString *strURL = [NSString stringWithFormat:@"http://www.abc.com/phpFile.php?number=%@&name=%@&lastname=%@", number, firstName, lastName];
strURL  = [strURL stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]

NSData *dataURL = [NSData dataWithContentsOfURL:[NSURL URLWithString:strURL]];
        NSString *strResult = [[NSString alloc] initWithData:dataURL encoding:NSUTF8StringEncoding];

        NSLog(@"%@", strResult);
NSString *strURL = [NSString stringWithFormat:@"http://www.abc.com/phpFile.php?number=%@&name=%@&lastname=%@", number, firstName, lastName];
strURL  = [strURL stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]

NSData *dataURL = [NSData dataWithContentsOfURL:[NSURL URLWithString:strURL]];
        NSString *strResult = [[NSString alloc] initWithData:dataURL encoding:NSUTF8StringEncoding];

        NSLog(@"%@", strResult);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文