Note that there are some explanatory texts on larger screens.

plurals
  1. POpost data to PHP script from iOS
    primarykey
    data
    text
    <p>I am trying the following code that executes after user enter data in fields (title, desc, city) and then clicks save. </p> <pre><code>- (IBAction)saveDataAction:(id)sender { NSString *lEventTitle = [NSString stringWithFormat:@"var=%@",eventTitle.text]; NSString *lEventDesc = [NSString stringWithFormat:@"var=%@",eventDescription.text]; NSString *lEventCity = [NSString stringWithFormat:@"var=%@",eventCity.text]; NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"http://mydomain.com/ios/form.php"]]; [request setHTTPMethod:@"POST"]; [request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"content-type"]; //this is hard coded based on your suggested values, obviously you'd probably need to make this more dynamic based on your application's specific data to send NSString *postString = [[NSString alloc] initWithFormat:@"title=%@&amp;description=%@&amp;city=%@", lEventTitle, lEventDesc, lEventCity]; NSString *clearPost = [postString stringByReplacingOccurrencesOfString:@"var=" withString:@""]; NSLog(@"%@", clearPost); [request setHTTPBody:[clearPost dataUsingEncoding:NSUTF8StringEncoding]]; [request setValue:clearPost forHTTPHeaderField:@"Content-Length"]; [NSURLConnection connectionWithRequest:request delegate:self]; NSLog(@"%@", request); } </code></pre> <p>When I NSLog the clearPost string (string containing the variables to be sent to server), it shows:</p> <pre><code>title=xmas&amp;description=Celebration&amp;city=NY </code></pre> <p>on the PHP end, I have simple as:</p> <pre><code>&lt;?php $title = $_POST['title']; $description = $_POST['description']; $city = $_POST['city']; echo "Title: ". $title; echo "Description: ". $description; echo "City: ". $city; ?&gt; </code></pre> <p>Just trying to get data on PHP so that later I can manipulate it. Right now when I execute the </p> <p>domain.com/ios/form.php, it shows the title, description and city empty.</p> <p>Sorry but I am very new to iOS and Objective-C.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload