我試圖將設備令牌傳遞給我的服務器,但面臨一些問題,因爲一切工作在我的數據庫中它存儲爲空我不在這裏我做錯了。設備令牌傳遞給服務器空
-(void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
{
const char* data = [deviceToken bytes];
NSMutableString * token = [NSMutableString string];
for (int i = 0; i < [deviceToken length]; i++) {
[token appendFormat:@"%02.2hhX", data[i]];
}
NSString *urlString = [NSString stringWithFormat:@"http://localhost/pushnofiy/insert.php?token=%@",token];
NSURL *url = [[NSURL alloc] initWithString:urlString];
NSLog(@"token %@",urlString);
NSURLRequest *urlRequest = [NSURLRequest requestWithURL:url];
NSLog(@"request %@ ",urlRequest);
NSData *urlData;
NSURLResponse *response;
urlData = [NSURLConnection sendSynchronousRequest:urlRequest returningResponse:&response error:nil];
}
如果我打印urlString
其顯示設備令牌,但我不知道爲什麼它不是在數據庫中插入。
代碼
<?php
mysql_connect(localhost,$username);
@mysql_select_db($database) or die("Unable to find Database");*/
include "db.php";
$token =$_GET["token"];
$query = "INSERT INTO notifi (token) VALUES('$token')";
mysql_query($query) or die (mysql_error("error"));
mysql_close();
?>
我不知道是怎麼回事錯誤的,我請人說不出哪裏我做錯了。
謝謝。
*旁註:*停止使用已棄用的mysql_ *函數。改爲使用[MySQLi](http://php.net/manual/en/book.mysqli.php)或[PDO](http://php.net/manual/en/book.pdo.php)。這是一個很好的[教程](http://j.mp/PoWehJ)PDO。此外,你的代碼受到SQL注入攻擊,你允許直接在查詢中插入GET值。 – Raptor
存儲空字符串或未插入記錄?您的PHP代碼有語法錯誤,即無法運行。 – Raptor
@ShivanRaptor請告訴我,在我們能幫忙之前,我會在什麼地方做錯的,它確實會幫助我們完整 – user3349668