title: How to update a MySQL Database with UITextField content in Xcode 5?
body: <p>I'm building my first iPhone application which pulls clients network information from a MySQL database and displays the content in UITextFields. This is all working fine, the correct information is pulled down and the client name added to a UITableView, then when the client name is selected a segue is performed that moves to the second view controller where the text fields are populated with the rest of the clients information.</p>
  
  <p>This is the PHP code used to get this working;</p>
  
  <pre><code>&lt;?php
  
  $ipaddress = $_GET['ipaddress'];
  $netpass = $_GET['netpass'];
  $wifipass = $_GET['wifipass'];
  $domain = $_GET['domain'];
  $name = $_GET['name'];
  
  
   $con=mysqli_connect("localhost","drift","Drift","drift"    );
   // Check connection
   if (mysqli_connect_errno())
  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }
  
  $sql = "UPDATE networks SET Ip='$ipaddress', Domain='$domain', Wifi='$wifipass',     Password='$netpass$  WHERE Name = '$name'";
  
  mysqli_query($con,$sql);
  
  
  $result = mysqli_query ($con, "SELECT * FROM networks");
  
  mysqli_close($con);
  
  ?&gt;
  </code></pre>
  
  <p>(I used this tutorial to get as far as I have so far 
  <a href="http://codewithchris.com/iphone-app-connect-to-mysql-database/" rel="nofollow">http://codewithchris.com/iphone-app-connect-to-mysql-database/</a> 
  If any more information is needed with regards to the coding of the app itself this can be found in the above link, I have no idea which parts of the existing code you may need to see in order to assist as I am completely new to Php, MySQL and JSON.)</p>
  
  <p>Now, what I want to do is make it so that the information which has been pulled from the mysql database and displayed in the UITExtFields can be edited and then saved back to the database (to update existing records only not to add new records). I've looked around but I just can't find a solution that shows the required PHP and how to then use the PHP file in Xcode to update the MySQL data.</p>
  
  <p>I've nearly got the PHP side working, I have managed to create a script that updates the database from a web form so what I really need is is to know how to pass the value of UITextField.text to the php file instead of the value of the web form?</p>
  
  <p>I can post the update form I have if it will help? </p>
  
  <p>Thanks for your time, any help will be greatly appreciated.</p>
  
  <p>Update 2:</p>
  
  <pre><code>     NSString *url = [NSString stringWithFormat:@"http://server.com/updatedb.php?name=%@&amp;ipaddress=%@&amp;netpass=%@&amp;wifipass=%@&amp;domain=%@", schoolnameField.text, ipaddressField.text, _netpassField.text,_wifipassField.text,_domainField.text];
  
  // build the request
  NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
  [request setURL:[NSURL URLWithString:url]];
  [request setHTTPMethod:@"POST"];
  NSMutableData *body= [NSMutableData data];
  [request setHTTPBody:body];
  
  // getting answer from the server.
  // you can echo message from the server let's say :"Update finish" or something like     that...
  NSData *returnData = [NSURLConnection sendSynchronousRequest:request     returningResponse:NULL error:nil];
  
  NSString *returnString = [[NSString alloc] initWithData:returnData     encoding:NSUTF8StringEncoding];
  NSLog(@"returned: %@", returnString);
  </code></pre>