Xcode将带有url的变量发送到php页面,在php代码中为select语句检索变量

Xcode将带有url的变量发送到php页面,在php代码中为select语句检索变量,php,ios,mysql,objective-c,Php,Ios,Mysql,Objective C,我试图调用一个连接到mysql数据库的php页面。我已经成功地将表中的所有数据加载到xcode中的UITableView中 我现在需要做的是更改select语句,以从具有特定ID的表中加载数据 这是我的xcode: NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"http://server/phppage.php"]]; request.HTTPMethod

我试图调用一个连接到mysql数据库的php页面。我已经成功地将表中的所有数据加载到xcode中的UITableView中

我现在需要做的是更改select语句,以从具有特定ID的表中加载数据

这是我的xcode:

NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"http://server/phppage.php"]];
    request.HTTPMethod = @"POST";
    [request setValue:@"application/x-www-form-urlencoded; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
    NSMutableDictionary *postDict = [[NSMutableDictionary alloc] init];
// here is where the variable i want to send 
    [postDict setValue:@"1" forKey:@"CategoryType"];
    NSData *jsonData = [NSJSONSerialization dataWithJSONObject:postDict options:0 error:nil];
    NSString *urlString =  [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
    NSString *stringData = [[NSString alloc] initWithFormat:@"jsonRequest=%@", urlString];
    NSData *requestBodyData = [stringData dataUsingEncoding:NSUTF8StringEncoding];
    request.HTTPBody = requestBodyData;
    NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:request delegate:self];
    if (!theConnection) {
        NSMutableData *responseData = nil;
        NSLog(@"connection failes");
    }
这是php页面:-

<?php

// Create connection
$con=mysqli_connect("","","database","") or die ( mysqli_error($MySQL_Handle) );
$sSQL= 'SET CHARACTER SET utf8';
mysqli_query($con,$sSQL) or die ('Can\'t charset in DataBase');

// this is where the variable sent from the xcode is received

$cid = $GET_["CategotyType"];
$sql = "SELECT * FROM itesttable where phone = $cid";

if ($result = mysqli_query($con, $sql))
{
  $resultArray = array();
  $tempArray = array();
  while($row = $result->fetch_object())
  {
  $tempArray = $row;
     array_push($resultArray, $tempArray);
  }
  echo json_encode($resultArray);
}
mysqli_close($con);
?>
我不知道错误是在xcode中,我以错误的方式发送变量CategoryType,还是在php中,我以错误的方式检索变量……

列电话是一个整数列?因为只有在它是的情况下,您才可以访问它。如果是VARCHAR,则必须将其更改为:

$sql = "SELECT * FROM testable WHERE phone = '".$cid."'";
然而,这是一个GET方法,为什么不通过URL访问它呢

http://wwww.yourdomain.ext/phpPage.php?CategoryType=YOUR_VALUE

在PHP代码中有一个输入错误:查询CategotyType而不是CategoryType的值


另外,您真的非常想了解什么是SQL注入漏洞,以及如何在PHP中防止这些漏洞。

谢谢,它很有效。。。我将检查通过url访问的方法,我从未听说过它…我正在尝试以下代码将categoryID值传递到php页面。。。。NSString*CategoryID=@2;NSString*strURL=[NSString stringWithFormat:@;NSURL*url=[NSURL URLWithString:strURL];NSURLRRequest*request=[NSURLRRequest requestWithURL:url];[NSURLConnection connectionWithRequest:request委托:self];但是,我一直在取回categoryID=0的条目!!!感谢您的更正,而且似乎SQL注入漏洞是我真正需要注意的,感谢您提醒我注意它。