Connect to database in android <p>I used the login code to login through simple android application , I've created mydatabase also created the whole java classes needed and the xml files, the result always gives me "Invalid username or password" even though the username and the password are correct as inserted in the DB ,, the app runs with no errors</p> <p>this is the MainActivity java class:</p> <pre><code>package com.logintest.fh; import java.io.IOException; public class MainActivity extends Activity { /** Called when the activity is first created. */ Button login; String name="",pass=""; EditText username,password; TextView tv; byte[] data; HttpPost httppost; StringBuffer buffer; HttpResponse response; HttpClient httpclient; InputStream inputStream; SharedPreferences app_preferences ; List&lt;NameValuePair&gt; nameValuePairs; CheckBox check; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); app_preferences = PreferenceManager.getDefaultSharedPreferences(this); username = (EditText) findViewById(R.id.username); password = (EditText) findViewById(R.id.password); login = (Button) findViewById(R.id.login); check = (CheckBox) findViewById(R.id.check); String Str_user = app_preferences.getString("username","0" ); String Str_pass = app_preferences.getString("password", "0"); String Str_check = app_preferences.getString("checked", "no"); if(Str_check.equals("yes")) { username.setText(Str_user); password.setText(Str_pass); check.setChecked(true); } login.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { name = username.getText().toString(); pass = password.getText().toString(); String Str_check2 = app_preferences.getString("checked", "no"); if(Str_check2.equals("yes")) { SharedPreferences.Editor editor = app_preferences.edit(); editor.putString("username", name); editor.putString("password", pass); editor.commit(); } if(name.equals("") || pass.equals("")) { Toast.makeText(MainActivity.this, "Blank Field..Please Enter", Toast.LENGTH_LONG).show(); } else { try { httpclient = new DefaultHttpClient(); httppost = new HttpPost("http://10.0.0.1/my_folder_inside_htdocs/check.php"); // Add your data nameValuePairs = new ArrayList&lt;NameValuePair&gt;(2); nameValuePairs.add(new BasicNameValuePair("username", name.trim())); nameValuePairs.add(new BasicNameValuePair("password", pass.trim())); httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs)); // Execute HTTP Post Request response=httpclient.execute(httppost); ResponseHandler&lt;String&gt; responseHandler = new BasicResponseHandler(); final String response = httpclient.execute(httppost, responseHandler); System.out.println("Response : " + response); if(response.equalsIgnoreCase("User Found")){ runOnUiThread(new Runnable() { public void run() { Toast.makeText(MainActivity.this,"Login Successfull", Toast.LENGTH_SHORT).show(); } }); //startActivity(new Intent(MainActivity.this, UserPage.class)); Move_to_next(); }else{ Toast.makeText(MainActivity.this, "Invalid Username or password", Toast.LENGTH_LONG).show(); } } catch (Exception e) { Toast.makeText(MainActivity.this, "error"+e.toString(), Toast.LENGTH_LONG).show(); } } } }); check.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { // Perform action on clicks, depending on whether it's now checked SharedPreferences.Editor editor = app_preferences.edit(); if (((CheckBox) v).isChecked()) { editor.putString("checked", "yes"); editor.commit(); } else { editor.putString("checked", "no"); editor.commit(); } } }); } public void Move_to_next() { startActivity(new Intent(MainActivity.this, UserPage.class)); } } </code></pre> <p>the UserPage an empty page I want the user to go to after logging in</p> <p>this is my php file : <pre><code>try { $db = new PDO("mysql:host=$hostname_localhost;dbname=mydatabase", $username_localhost, $password_localhost); echo "Connected to database"; // check for connection $username = $_POST['myusername']; $password = $_POST['mypassword']; $db-&gt;setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING); $sql = "select * from mydatabase.tbl_user where username = '".$username."' AND password = '".$password. "'"; $result = $db-&gt;query($sql); foreach ($result as $row) { echo "&lt;br/&gt; success"; } $db = null; // close the database connection } catch(PDOException $e) { echo $e-&gt;getMessage(); } ?&gt; </code></pre> <p>any ideas of what the problem might be ?</p>