我试图将设备令牌传递给我的服务器,但面临一些问题,因为一切工作在我的数据库中它存储为空我不在这里我做错了。设备令牌传递给服务器空
-(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