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 7024059
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T23:47:26+00:00 2026-05-27T23:47:26+00:00

.PHP file successfully works by creating a db connection and inserting sql. My only

  • 0

.PHP file successfully works by creating a db connection and inserting sql.
My only conclusion then it is somewhere in the .java activity
..and yes I have set INTERNET PERMISSIONS within manifest.

MY ERROR: 01-03 21:56:05.784: W/System.err(1398): android.os.NetworkOnMainThreadException

@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
            super.onCreate(savedInstanceState);
            //setContentView(R.layout.email);
            try {
                postInternetData();
            } catch (Exception e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }

private void postInternetData() {
    HttpClient httpclient = new DefaultHttpClient();
    HttpPost post = new HttpPost("http://www.example.com/app/insert_tag.php");

    try{            
        List<NameValuePair> formparams = new ArrayList<NameValuePair>();
        formparams.add(new BasicNameValuePair("name", "android"));

        post.setEntity(new UrlEncodedFormEntity (formparams));

        HttpResponse response = httpclient.execute(post);

        } catch (ClientProtocolException e) {
            // TODO Auto-generated catch block
        } catch (IOException e) {
            // TODO Auto-generated catch block
        }   

    }

<?php
// CREATE the connection
$connection = mysql_connect('XXXXXXXXXXX.db.godaddy.com','XXXXXXXXXXX','XXXXXXXXXXX');
if(!$connection) {
    echo 'failure to connect host';
}

$mysql_select_db = mysql_select_db('XXXXXXXXXXX', $connection);

if(!$mysql_select_db) {
    echo 'failure to select db';
}

$name = $_POST['name'];

$qry = "INSERT INTO httptest(id, name) VALUES ('', '" . $name . "');";

$result = mysql_query($qry, $connection);
IF (!$result){
    echo 'failure to query db';
} else {
    echo $result;
}
?>    

After hours of troubleshooting through stackoverflow examples and man files, I fold.
Is there anything that stands out to you?
Thanks.

  • 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-05-27T23:47:27+00:00Added an answer on May 27, 2026 at 11:47 pm

    As of Android 3.0 if you have any network operations (eg. connecting to your site) on the main (aka GUI) thread, the application throws NetworkOnMainThreadException. Try testing in an emulator running 2.2 to see if it works (and there are no other bugs in your code). Otherwise to make it work on 3.x and 4.x, you’ll need to take a look at threading in Android. A tutorial can be found here

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

Sidebar

Related Questions

This is user.php: include(databse.php);//retrieving successfully first name and lastname from databse file into user.php
I am loading a .php file into a div I created. I can successfully
I have big trouble with file uploads with php. My own tests are successful
PHP file.php arg1 arg2 Now I want to hardcode arg1 and arg2 into file.php
php file.php & How to get PID of the background process in file.php ?
In php I have open a .php file and want to evaluate certain lines.
I have an index.php file which has to process many different file types. How
i have a php file launching my exe. the exe does cout and the
I have a PHP file, Test.php, and it has two functions: <?php echo displayInfo();
I have a php file which I will be using as exclusively as an

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.