Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9007229
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T01:37:53+00:00 2026-06-16T01:37:53+00:00

i am trying to insert Latitude and Longitude value in mysql data base but

  • 0

i am trying to insert Latitude and Longitude value in mysql data base but it show the following error

  1. Error in http connection
    org.apache.http.conn.HttpHostConnectException: Connection to
    *http://localhost
    refused*

    //My main.java code is :
    
    public void insertdata()
    {
    ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
     nameValuePairs.add(new BasicNameValuePair("Lat","34"));
    nameValuePairs.add(new BasicNameValuePair("Lon","72"));
    
    //http post
    try{
        HttpClient httpclient = new DefaultHttpClient();
        HttpPost httppost = new      
       HttpPost("http://localhost/androidconnection/insertdata.php");
        httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
        HttpResponse response = httpclient.execute(httppost);
        HttpEntity entity = response.getEntity();
        InputStream is = entity.getContent();
        Log.i("postData", response.getStatusLine().toString());
    }
    
    catch(Exception e)
    {
        Log.e("log_tag", "Error in http connection "+e.toString());
    }           
    

    }

    //at server side my php insertion code is “insertdata.php”

     <?php
        mysql_connect("localhost","root","");
         mysql_select_db("PeopleData");
       //retrieve the data
       $lat = $_POST['lat'];
      $lon = $_POST['lon'];
    
      $sql = "INSERT INTO coords (Lat, Lon) VALUES('$lat', '$lon')";
    
           if (!mysql_query($sql, $sqlCon))
        {
            die('Error: ' . mysql_error());
         }
       else
        {
          //echo "1 record added";
           }
    
                ?>
    
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T01:37:55+00:00Added an answer on June 16, 2026 at 1:37 am

    localhost refers to the current machine on which the code is running, which in this case is Android phone(or emulator). And in order to access the host computer from android emulator, you can use the ip address: 10.0.2.2

    Change your url as follows:

    The line HttpPost("http://localhost/androidconnection/insertdata.php");
    should look like this : HttpPost("http://10.0.2.2/androidconnection/insertdata.php");

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

While trying to insert data to my SQl db i get the following error
Am trying to insert XML into XML Column.. getting following error: . Msg 6819,
I am trying to insert data to a new empty table. But I keep
Im trying to insert data into a table in MySQL. I found/modified some code
I'm trying to insert data into a database when there is no network, but
Im trying to insert values in a core data entity, but when I try
when trying to insert data into my sqlite db I receive a logcat error
I am trying to store latitude and longitude information in MySQL. I am using
I get the data type mismatch in criteria expression error when trying insert a
I am trying to fetch Gps latitude and longitude, but i am having a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.