0

help please

i am trying to make login form using php and android.But problem in making connection between php MySql and android.

When i use 127.0.0.1 ,php file is accessible through browser but on android cell it says

connection refused and when i use 10.0.2.2, php file not accessible through browser and on android cell it says

connection timeout

Here is my Code

            httpclient=new DefaultHttpClient();
            httppost= new HttpPost("http://10.0.2.2/my_folder_inside_htdocs/check.php"); // make sure the url is correct.
            //add your data
            nameValuePairs = new ArrayList<NameValuePair>(2);
            // Always use the same variable name for posting i.e the android side variable name and php side variable name should be similar, 
            nameValuePairs.add(new BasicNameValuePair("name",et.getText().toString().trim()));  // $Edittext_value = $_POST['Edittext_value'];
            nameValuePairs.add(new BasicNameValuePair("password",pass.getText().toString().trim())); 
            httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
            //Execute HTTP Post Request
            response=httpclient.execute(httppost);
            // edited by James from coderzheaven.. from here....
            ResponseHandler<String> responseHandler = new BasicResponseHandler();
            final String response = httpclient.execute(httppost, responseHandler);
            System.out.println("Response : " + response); 

            runOnUiThread(new Runnable() {
                public void run() {
                    tv.setText("Response from PHP : " + response);
                    dialog.dismiss();
                }
            });
4

2 Answers 2

1

Use your ip address in the HttpPost

   httppost= new HttpPost("http://ipaddress/my_folder_inside_htdocs/check.php"); 

I think this will help you

Sign up to request clarification or add additional context in comments.

Comments

0

You cannot use 10.0.2.2 on an Android device. Do you mean an Android device when you write android cell? 10.0.2.2 is for your app running in an emulator with the server on the same pc as your emulator.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.