title: Android login activity using mysql database
body: <p>Hi I am new to android and I am developing an app which has a login screen.</p>
  
  <p>I have tried many tutorials but I am not sure how to connect the mysql database to my android app. In all the tutorials they have used php to connect the android app to the database.</p>
  
  <p>What I want to know is that where exactly do I need to place the php file and where and how I need to create the php file.</p>
  
  <p>I am creating the database using mysql workbench.</p>
  
  <p>I am using eclipse 4.2 to write the java code.</p>
  
  <p>Hi i am using the following code to check whether the user name i entered is correct or not along with the php code but the problem is that it always gives incorrect username.</p>
  
  <pre><code>String response = null;
  try {
  response = CustomHttpClient.executeHttpPost("http://192.168.3.27/abc/check.php", postParameters);  //Enetr Your remote PHP,ASP, Servlet file link
  String res=response.toString();
  // res = res.trim();
  res= res.replaceAll("\\s+","");
  //error.setText(res);
  error.setText(res);
  if(res.equals("1")){
      Intent myIntent = new Intent(LoginActivity.this, HomeActivity.class);           
  startActivity(myIntent);
  
  }
  else
  error.setText("Sorry!! Incorrect Username or Password");
  </code></pre>
  
  <p>This is my php code.</p>
  
  <pre><code>&lt;?php
  $un=$_POST['username'];
  $pw=$_POST['password'];
  //connect to the db
  $user = ‘root’;
  $pswd = ‘root’;
  $db = ‘mylogin’;
  $conn = mysql_connect(‘localhost’, $user, $pswd);
  mysql_select_db($db, $conn);
  //run the query to search for the username and password the match
  $query = “SELECT * FROM userpass WHERE login_id = ‘$un’ AND login_pass = ‘$pw’”;
  $result = mysql_query($query) or die(“Unable to verify user because : ” . mysql_error());
  //this is where the actual verification happens
  if(mysql_num_rows($result) &gt; 0)
  
  echo 1;  // for correct login response
  else
  echo 0; // for incorrect login response
  ?&gt;
  </code></pre>