【发布时间】:2015-08-06 06:00:28
【问题描述】:
我正在尝试向我发送 POST 方法请求,但是当发送帖子时,存储在数据库中的数据为空,我没有得到我发送的值,这是我尝试过的:
NSString *queryString = [NSString stringWithFormat:@"http://localhost/json/insertData.php?username=test&password=test"];
NSMutableURLRequest *theRequest=[NSMutableURLRequest requestWithURL:[NSURL URLWithString: queryString] cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60.0];
[theRequest setHTTPMethod:@"POST"];
NSURLConnection *con = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
一切都很好,只有当数据被发送并且我检查数据库时我得到了空值,请问错误在哪里。
这是我的 PHP 文件的代码:
<?php
$host = "localhost";
$user = "root";
$pass = "root";
$db = "Users";
$con = mysqli_connect($host,$user,$pass);
if(!$con)
{
die("Can't connect to mysql server!");
}
$db_select = mysqli_select_db($con,$db);
if(!$db_select)
{
die("Can't get the selected db!");
}
$id = "11";
$username = $_POST['username'];
$password = $_POST['password'];
$email = "any1@any1.com";
$gsm = "91111111";
$query = "INSERT INTO Logins VALUES($id,'$username','$password','$email',$gsm)";
$query_exec = mysqli_query($con,$query);
if(!$query_exec)
{
die("Can't insert data");
}
?>
【问题讨论】:
-
请添加您的insertData.php的相关代码。
-
好的,问题已编辑,代码已添加
标签: php ios objective-c xcode xcode5