title: POST data to a PHP method from Swift
body: <p>I'm trying to post some info to my PHP file from Swift.
  My php file is executed, but the posted variables just don't get through to the php file. What am I doing wrong?</p>
  
  <p>Swift code:</p>
  
  <pre><code>@IBAction func buttonPress(sender: AnyObject) {
  
          let request = NSMutableURLRequest(URL: NSURL(string: "http://www.domain.com/php_swift_test/insert.php")!)
          request.HTTPMethod = "POST"
  
          let postString = "a=test&amp;b=bla"
          request.HTTPBody = postString.dataUsingEncoding(NSUTF8StringEncoding)
  
          let task = NSURLSession.sharedSession().dataTaskWithRequest(request) {
              data, response, error in
  
              if error != nil {
                  print("error=\(error)")
                  return
              }
  
              print("response = \(response)")
  
              let responseString = NSString(data: data!, encoding: NSUTF8StringEncoding)
              print("responseString = \(responseString)")
          }
          task.resume()
      }
  </code></pre>
  
  <p>PHP code:</p>
  
  <pre><code>&lt;?php
      @session_start();
      @ob_start();
  
      $host='localhost';
      $user='test';
      $password='Passw0rd99';
      $db_name="mysql_test"; 
  
      $connection = mysql_connect($host,$user,$password);
  
      $a = $_POST['a'];
      $b = $_POST['b'];
  
      if(!$connection){
          die('Connection Failed');
      }
      else{
          $dbconnect = @mysql_select_db($db_name, $connection);
  
          if(!$dbconnect){
              die('Could not connect to Database');
          }
          else{
              $query = "INSERT INTO res_club (FirstName, LastName) VALUES ('$a','$b')";
              mysql_query($query, $connection) or die(mysql_error());
  
              echo 'Successfully added.';
              echo $query;
              echo $a.$b;
          }
      }
  ?&gt;
  </code></pre>
  
  <p>An empty row is added to the database, with no first name and last name. The PHP file doesn't get the <code>$_Post['a']</code> and b</p>
  
  <p>The echo statement, <code>echo $a.$b</code> stays blank too. No errors are shown.</p>