上传到mysql服务器无法正常工作
我需要将数据添加到我的mysql数据库中。但是下面的实际数据库中没有添加任何内容的是我的xcode,下面是我的php代码。 似乎无法理解为什么它不起作用? 任何建议/你能看到错误吗?
-(void) postMessage:(NSString*) teamid withPlayerid:(NSString *) playerid withFixtureid:(NSString *) fixtureid withEventid:(NSString *) eventid withHalfid:(NSString *) halfid{ //check isnt receiving two anit paramters if(teamid !=nil && playerid !=nil && fixtureid !=nil && eventid !=nil && halfid !=nil){ NSMutableString *postString = [NSMutableString stringWithString:kPostURL]; [postString appendString:[NSString stringWithFormat:@"?%@=%@",kTeamid, teamid]]; //makes kname equal to name [postString appendString:[NSString stringWithFormat:@"&%@=%@", kPlayerid , playerid]]; [postString appendString:[NSString stringWithFormat:@"?%@=%@",kFixtureid, fixtureid]]; //makes kname equal to name [postString appendString:[NSString stringWithFormat:@"&%@=%@", kEventid , eventid]]; [postString appendString:[NSString stringWithFormat:@"?%@=%@",kHalfid, halfid]]; //makes kname equal to name [postString setString:[postString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]; NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:postString]]; [request setHTTPMethod:@"POST"]; postConnection = [[NSURLConnection alloc] initWithRequest:request delegate:self startImmediately:YES]; NSLog(@"%@",teamid); NSLog(@"%@",KTeamid); } } -(IBAction)prop1Button:(id)sender{ NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults]; // getting an NSString NSString *myString = [prefs stringForKey:@"1 - Prop"]; _textField3.text = myString; [self postMessage: self.textField2.text withPlayerid:self.textField3.text withFixtureid:self.textField3.text withEventid:self.textField3.text withHalfid:self.textField3.text]; _textField2.text = nil; _textField3.text = nil; dropGoalCounter ++; [[NSNotificationCenter defaultCenter] postNotificationName:@"DoUpdateLabel" object:nil userInfo:nil]; [self dismissViewControllerAnimated:YES completion:nil]; }
这是我插入数据库的php代码
编辑!!! 现在,这会在数据库中输入一个新条目,但由于NSString,所有字段都是空白的,而在数据库中,列是整数。 然而,当我改变PHP到这个
$teamid = (int)$_POST["teamid"] $playerid = (int)$_POST["playerid"]; $fixtureid = (int)$_POST["fixtureid"]; $eventid = (int)$_POST["eventid"]; $half = (int)$_POST["halfid"];
它根本不会向数据库添加条目。 有什么建议么?
发现问题:
Xcode中:
[request setHTTPMethod:@"POST"]; ^^^^^
PHP:
$teamid = $_GET["teamid"]; ^^^----hmmmmm. not $_POST
除此之外,您还容易受到SQL注入攻击
$ result = mysqli_query($ connection,$ query);
echo $query;
我看起来像这样,工作没有错误
S [postString appendString:[NSString stringWithFormat:@“?%@ =%@”,kHalfid,halfid]]; 有一个 ? 代替 &。
- 从Iphone上传Jcrop不正确的方向,我怎么办?
- 如何在iOS Swift 3中encryptionAES 256 CBC,如larvel encrypt()方法
- 在iOS中parsing具有相同名称但在不同字段中的属性
- 针对来自同一服务器的多个应用程序推送通知的限制
- 警告:stream_socket_client():无法设置私钥文件
- didCreatePaymentResult stripeID是一个card_令牌,似乎无法保存给客户
- PHP:“注意:未定义的variables”,“注意:未定义的索引”和“注意:未定义的偏移量”
- 应用程序与服务器端的会话pipe理
- 无法将数据从iPhone应用程序插入到MySQL数据库