php - Values are not inserting on mysql database from android device

public class MainActivity extends Activity {

private ArrayList<NameValuePair> nameValuePairs;
private DefaultHttpClient httpclient;
private HttpPost httppost;
private HttpResponse response;

protected void onCreate(Bundle savedInstanceState) {

    Thread thread = new Thread(new Runnable() {
        public void run() {
            try {
                InputStream is = null;
                // http post
                ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
                nameValuePairs.add(new BasicNameValuePair("post",
                        .add(new BasicNameValuePair("price", "14:30"));
                nameValuePairs.add(new BasicNameValuePair("description",

                try {
                    HttpClient httpclient = new DefaultHttpClient();
                    HttpPost httppost = new HttpPost(
                    httppost.setEntity(new UrlEncodedFormEntity(
                    HttpResponse response = httpclient.execute(httppost);
                    HttpEntity entity = response.getEntity();
                    is = entity.getContent();
                } catch (Exception e) {
                            "Error in http connection" + e.toString());
            } catch (Exception e) {



    // TODO Auto-generated method stub


public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(, menu);
    return true;

And here's the php part:


      $con=mysql_connect("","xxxxx", "xxxxxxxx") or  die('Could not     connect: ' . mysql_error());

      $sql="INSERT INTO test (post,price,description) VALUES ('$post','$issue','$description')";


           echo "Error in query: ".mysql_error();
      else echo "no data endered";

I tried this code and created a table on 000webhost and uploaded my php file there.But whenever I run the application from my android phone or emulator,on both case,the table is not updating with the values I want to insert,and also I opened the php file with my browser which I saved to htdocs on xampp and browser shows that:

" mysql_connect(): A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. in C:\xampp\htdocs\Echo\mysql_con.php on line 5"

Now,how can I get this working,specially into my android phone.I am new to android and this code is for just learning purpose.

Edit: I haven't posted the log because it is clear and no error is showing




Is you localhost running? check if yes then run the same page on your localhost as you are trying to inserting the data from app and print the same

People are also looking for solutions to the problem: javascript - Disable a button in page1 based on a textbox value from page2 (AJAX, PHP,jQuery)


Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.