Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Create a simple web service that takes the parameters you need to pass and add them to a database. Here's a simple example with PHP to save a username and password to a mysql database. Below it you will find how to send it from within the App using a POST request:</p> <pre><code>&lt;? // check if email and password are not blank if(trim($_POST['email']) != '' &amp;&amp; trim($_POST['password']) != '') { $emailQuery = strtolower(mysql_real_escape_string($_POST['email'])); $passwordQuery = md5($_POST['password']); $host = 'localhost'; $dbuser = 'username'; $dbpassword = 'password'; $dbname = 'databasename'; /* connect to the db */ $link = mysql_connect($host,$dbuser,$dbpassword) or die ('Cannot connect to the DB'); mysql_select_db($dbname,$link) or die('Cannot select the DB'); /* insert the data into the db */ $query = "INSERT INTO members VALUES ('','$emailQuery','$passwordQuery')"; mysql_query($query) or die('Errant query: '.$query); echo "Database updated"; @mysql_close($link); } else echo "Mandatory parameters missing"; ?&gt; </code></pre> <p>Then from your App you can send the post request by using NSURLConnection. I am using a synchronous request for the sake of simplicity but recommend that you check the documentation for NSURLConnection and how implement asynchronous requests and read the response through delegate methods:</p> <pre><code>// login and password are both UITextField instances NSString *myRequestString = [NSString stringWithFormat:@"email=%@&amp;password=%@",self.login.text, self.password.text]; NSData *myRequestData = [NSData dataWithBytes:[myRequestString UTF8String] length:[myRequestString length]]; NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:@"http://domain.com/webservice.php"]]; [request setHTTPMethod: @"POST"]; [request setHTTPBody: myRequestData]; NSData *returnData = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil]; NSString *returnString = [[NSString alloc] initWithData:returnData encoding:NSUTF8StringEncoding]; // To see what the response from your server is, NSLog returnString to the console or use it whichever way you want it. NSLog (@"%@", returnString); </code></pre> <p>I hope it helps. Rog</p>
    singulars
    1. This table or related slice is empty.
    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.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      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