title: Sending Data From iOS App to PHP Script
body: <p>I feel like this shouldn't be this complicated but here I am after spending the last 2 days trying to get this to work. I'm trying to send two variables from my iOS app to a php script I have on a server. The database adds an entry but the 2 information fields are blank. I'm alright with Objective C but new to PHP.</p>
  
  <p>PHP Code</p>
  
  <pre><code>&lt;?php
          $name = $_POST['name'];
          $comment = $_POST['comment'];
                      mysql_connect("Server","Username","Password");
                      mysql_select_db("comments");
                      mysql_query("INSERT INTO comments (id, name, comment) VALUES ('','$name','$comment')");
  ?&gt;
  </code></pre>
  
  <p>Objective C Code</p>
  
  <pre><code>NSString *name = @"Name1";
      NSString *comment = @"Comment1";
      NSString *myRequestString = [NSString stringWithFormat:@"&amp;name=%@&amp;comment=%@",name,comment];
      NSData *myRequestData =[myRequestString dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
      NSString *postLength = [NSString stringWithFormat:@"%d",[myRequestData length]];
      NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL: [NSURL URLWithString: @"http://www.notguiltyapp.com/harris.php"]];
  
      [request setHTTPMethod: @"POST"];
  
      [request setValue:postLength forHTTPHeaderField:@"Content-Length"];
      [request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"content-type"];
  
      // Set Request Body
      [request setHTTPBody: myRequestData];
      NSURLConnection *conn = [[NSURLConnection alloc]initWithRequest:request delegate:self];
  
      if(conn)
      {
          NSLog(@"Connection Successful");
      }
      else
      {
          NSLog(@"Connection could not be made");
      }
  </code></pre>