2014-04-17 147 views
1

我需要添加數據到我的mysql數據庫。當我在teamid上運行NSLOG時,它顯示7是正確的,但是當我在KTeamid上運行NSLOG時,它會回覆teamid。然而,沒有什麼被添加到實際的數據庫下面是我的Xcode和低於這是我的PHP代碼。似乎無法明白爲什麼它不起作用?任何建議/你能看到錯誤嗎?php上傳數據到mysql服務器

-(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 
include ("./inc/connect.inc.php"); 
$teamid = $_GET["teamid"]; 
$playerid = $_GET["playerid"]; 
$fixtureid = $_GET["fixtureid"]; 
$eventid = $_GET["eventid"]; 
$half = $_GET["halfid"]; 

$query = "INSERT INTO MatchEvent VALUES ('','$teamid','$playerid','$fixtureid','$eventid','$half')"; 

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

mysql_close(); 

?> 

感謝

我的PHP代碼

回答

0

我知道的是: 這裏有一個小k

[postString appendString:[NSString stringWithFormat:@"?%@=%@",kTeamid, teamid]]; 

在這裏你使用首都K. Mabye只是一個錯字?

NSLog(@"%@",KTeamid); 

編輯: 你繼續混合?當你附加數據時,你可以使用&。爲什麼?據我瞭解,你需要使用?符號僅適用於您通過的第一個值:www.URL.com?teamid = testTeamId 從那時起,您需要使用&符號來傳遞新值: www.URL.com?teamid=testTeamId & key2 = value2 & key3 = value3

如果這沒有幫助,你可以通過NSLog發佈URLString當一切都已被追加?

+0

對不起,這只是一個類型改正了我的答案。有什麼建議麼? – user3535330

相關問題