I try to send some text from my app to php, but somehow I never receive text. What 's wrong here?
NSString *name = [[NSString alloc]initWithString: @"Hello World"];
NSString *email = [[NSString alloc]initWithString: @"Ohai2u"];
NSString *urlString = [NSString stringWithFormat:@"http://www.myhosturlxyz.com/tracktxt.php?name=%@ email=%@",
[name stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding],
[email stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
NSURL *url = [[NSURL alloc] initWithString:urlString];
NSURLRequest *urlRequest = [NSURLRequest requestWithURL:url];
NSData *urlData;
NSURLResponse *response;
urlData = [NSURLConnection sendSynchronousRequest:urlRequest returningResponse:&response error:nil];
[url release];
The php I made is
<?php
$name = $_REQUEST['name'];
$email = $_REQUEST['email'];
$myFile = "tracktxtf.txt";
$fh = fopen($myFile, 'a') or die("can't open file");
fwrite($fh, "my posted var is " .$name $email "\n");
fclose($fh);
?>
Just a wild guess, but might you need & between name=%@ and email=%a, making it name=%@&email=%@?
Or, can you try using $_GET['name'] and $_GET['email'] instead of REQUEST? Perhaps try writing print_r($_REQUEST, true); print_r($_GET, true); to your debug file and see what it contains.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With