Im new to IOS and I am trying to obtain data from a php file in Json format. The way that I would like to obtain this data is by sending information from the app to the php sql query. I have tried the following:
IOS:
NSString *myRequestString = [NSString stringWithFormat:@"%@%@",@"ID",newsID];
NSLog(myRequestString);
NSData *myRequestData = [NSData dataWithBytes: [myRequestString UTF8String] length: [myRequestString length]];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc]init];
[request setURL:[NSURL URLWithString:@"http://domain.com/file.php"]];
[request setHTTPMethod: @"REQUEST"];
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"content-type"];
[request setHTTPBody: myRequestData];
NSData *returnData = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil]; //Or async request
NSError *error=nil;
NSArray *results = [NSJSONSerialization JSONObjectWithData:returnData options:0 error:&error];
PHP:
$query="SELECT news_description FROM newsTable WHERE newsID = ".$_REQUEST['ID'].";
$result=mysql_query($query);
while($row=mysql_fetch_assoc($result))
$output[]=$row;
print(json_encode($output));
I have researched some ideas but unfortunately it does not send the information to the php file. I have tried changing $_REQUEST to $_POST, also I created a variable in my php file to store $_POST but no luck. Any suggestions? Please help! Thank you!