Search code examples
phpobjective-cnsurlstringwithformat

NSUrl using stringwithformat to pass data to php page always returns sent value as zero


This is the objective-c code

NSString *CategoryID = @"2";
NSString *strURL =[NSString stringWithFormat:@"http://****/iCategoryItems.php?CategoryID=%@",CategoryID];
NSURL *url = [NSURL URLWithString:strURL];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[NSURLConnection connectionWithRequest:request delegate:self];

And this is the php code of the icategoryitems.php page

$cid = $GET_["CategoryID"];
$sql = "SELECT * FROM items where cat_id = '".$cid."' ";

however the code as-is always returns the items with cat_id = 0

Am I sending categoryID wrong way, or reading it from the php wrong way !


Solution

  • I think you mean:

    $cid = $_GET["CategoryID"];
           ^^^
    

    Your code is wiiiide open to sql injection attacks as well. You should be using PDO for your queries: http://php.net/manual/en/book.pdo.php