iPhone SDK: Running PHP script with parameters via app

Mars12343

New Member
I have a UISearchBar used for searching an xml document for matching words. I am making a request to a PHP script through the app. This php script creates a new xml file with the search results in it, and the app then parses the search results xml file and then displays the results.The problem is that when requesting the php script via the app, the script fails to create the xml results file on the remote server, however the search results file is created when running the script from a browser. I have checked all file permissions.Here is the code:App:\[code\]NSString *searchText = [[NSUserDefaults standardUserDefaults]objectForKey:@"searchParam"]; int randomID = arc4random() % 1000000;NSString *urlstr = [[NSString alloc] initWithFormat:@"http://server.com/search.php?search=%d&id=%d",searchText,randomID]; NSURL *url = [[NSURL alloc] initWithString:urlstr]; NSString *ans = [NSString stringWithContentsOfURL:url]; [urlstr release]; [url release]; NSLog(@"ans = %@",ans);\[/code\]PHP Script (search.php):\[code\]$srcDom = new DOMDocument;$srcDom->load('/var/www/html/xml/searchfile.xml');$xPath = new DOMXPath($srcDom);$searchParam = mysql_real_escape_string($_POST['search']);$searchID = mysql_real_escape_string($_POST['id']);echo "SEARCH ID = " . $searchID;$strxml = ""; $allEventsForVenue = $xPath->query( sprintf( "/Ticket/EventsPoints/Event[contains(PerformanceName,'$searchParam')]" ) ); foreach ($allEventsForVenue as $event) { $dstDom = new DOMDocument('1.0', 'utf-8'); $dstDom->appendChild($dstDom->createElement('EventsPoints')); $dstDom->documentElement->appendChild($dstDom->importNode($event, true)); echo $dstDom->saveXml(); $dstDom->formatOutput = true; $strxml .= $dstDom->saveXML(); $handle = fopen("/var/www/html/xml/searchresults$searchID.xml", "w"); fwrite($handle, $strxml); fclose($handle); }\[/code\]
 
Back
Top