gpt4 book ai didi

php - 上传到mysql服务器不工作

转载 作者:行者123 更新时间:2023-11-28 20:03:01 25 4
gpt4 key购买 nike

我需要将数据添加到我的 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代码

<?php
include ("./inc/connect.inc.php");
$teamid = (int)$_POST["teamid"];
$playerid = (int)$_POST["playerid"];
$fixtureid = (int)$_POST["fixtureid"];
$eventid = (int)$_POST["eventid"];
$half = $_POST["halfid"];

$query = "INSERT INTO MatchEvent (MatchEventID, TeamID, PlayerID,FixtureID,EventID,Half) VALUES ('','9','1','8','7','$half')";

mysql_query($query) or die(mysql_error("error"));

mysql_close();

?>

编辑!!!现在,这会在数据库中输入一个新条目,但假设由于 NSString 的缘故,所有字段都是空白的,并且在数据库中,列是整数。然而,当我将 php 更改为此时

$teamid = (int)$_POST["teamid"]
$playerid = (int)$_POST["playerid"];
$fixtureid = (int)$_POST["fixtureid"];
$eventid = (int)$_POST["eventid"];
$half = (int)$_POST["halfid"];

它根本不向数据库添加条目。有什么建议吗?

最佳答案

发现问题:

代码:

[request setHTTPMethod:@"POST"];
^^^^^

PHP:

$teamid = $_GET["teamid"];
^^^----hmmmmm. not $_POST

除此之外,您还容易受到 SQL injection attacks 的攻击

关于php - 上传到mysql服务器不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23137307/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com