title: What is the best way to create a login on iOS to MySQL database?
body: <p>I have a website which I can log into made in PHP. Now I'm trying to make the same login page on the iPad.</p>
  
  <p>I have two textfields and a login button and it's set up like this when I tap login:</p>
  
  <pre><code>-(IBAction)login:(id)sender {
      NSString *username = usernameTextfield.text; 
      NSString *password = passwordTextfield.text;
  
      NSString *anURL;
  
      anURL = @"http://www.mydomain.com/login.php";
  
      NSMutableURLRequest *request =[NSMutableURLRequest requestWithURL:[NSURL URLWithString:anURL]];
      [request setHTTPMethod:@"POST"];
  
      NSString *post =[[NSString alloc] initWithFormat:@"username=%@&amp;password=%@", username, password];
      [request setHTTPBody:[post dataUsingEncoding:NSASCIIStringEncoding]];
  
      NSURLResponse *response;
      NSError *err;
      NSData *responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:&amp;response error:&amp;err];
  
      NSString *dataStr = [NSString stringWithFormat:@"%@", responseData];
  
      [statusLabel setText:dataStr]; // This is just to see what data I get back…
  }
  </code></pre>
  
  <p>And this is my PHP file "login.php":</p>
  
  <pre><code>&lt;?php
  
  include("config.php"); //&lt;- db connection
  
  session_start();
  
  $message = "";
  
  $username = stripslashes(mysql_real_escape_string($_POST['username'])); 
  $password = stripslashes(mysql_real_escape_string($_POST['password']));
  
  $submit = $_POST["submit_login"];
  
  $md5_password = md5($password);
  
      $sql = "SELECT * FROM usr_table WHERE usr_name = '$username' and md5_password = '$md5_password'";
      $result = mysql_query($sql);
  
      $count = mysql_num_rows($result);
  
      if($count == 1) {
          $user_fetch = mysql_fetch_array($result);
          $_SESSION['usr_id'] = $user_fetch['usr_id'];
          $_SESSION['usr_name'] = $user_fetch['usr_name'];
  
          $message = "Login OK";
  
      } else {
          $message = "Login NOT OK";
      }
  
  echo $message;
  
  ?&gt; 
  </code></pre>
  
  <p>I just seem to get the data back in HEX format? How can I translate that and treat it in a good way? Am I logged in at this point or is it a better way of doing this?</p>
  
  <p>Thanks in advance,
  Viktor Gidlöf</p>