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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T03:16:40+00:00 2026-06-14T03:16:40+00:00

I have an Android java method that calls a remote php to insert data

  • 0

I have an Android java method that calls a remote php to insert data into a mysql table.

This is java code client side:

public static void insert(String email1, String email2) {
    List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
    nameValuePairs.add(new BasicNameValuePair("email1", email1));
    nameValuePairs.add(new BasicNameValuePair("email2", email2));

    try {
        DefaultHttpClient httpClient = new DefaultHttpClient();
        HttpPost httpPost = new HttpPost("myserver:8080/insert.php");
        httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
        HttpResponse httpResponse = httpClient.execute(httpPost);
        HttpEntity httpEntity = httpResponse.getEntity();
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    } catch (ClientProtocolException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    //How to catch and print php echo() here??
}

and this is the insert.php server side (re-edited):

<?php   
    $mysqli_connection = new mysqli("localhost:3306", "root", "password", "mydb");
    if ($mysqli_connection->connect_errno) {
        echo ("Connection Failure");
        exit();
    }


    $stmt = $mysqli->stmt_init();
    if ($stmt->prepare("INSERT INTO `mytable` (`email1`, `email2`) VALUES (?,?)")) {
        echo 'Success';
        $stmt->bind_param("ss", $_GET['email1'], $_GET['email2']);
        $stmt->execute();
        $stmt->close();
    } else {
        echo 'Error Inserting Content';
    }

    $mysqli->close();   
?>

When I call my java insert() method, no exception is returned, but no insert is done and mytable is empty.

  • 1) What is wrong?
  • 2) How can I see which error occured? How can I see a “log” of the the php-side execution?

Thank you very much.
Geltry

  • 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-14T03:16:41+00:00Added an answer on June 14, 2026 at 3:16 am

    Look into your HttpResponse/HttpEntity. There you should see either ‘Success’ or ‘Error Inserting Content’. You can also add the concrete errno and error string in your response to see, what’s really going wrong.

    You also mix HTTP POST and HTTP GET in your request. On the client side you use a HttpPost object and on the server side you expect the _GET variables to be set. You must use either GET or POST on both sides. Otherwise client and server won’t understand each other.

    With HttpEntity.getContent() you can read from an InputStream. Another approach would be to use EntityUtils.toString() to get a string representation of the response’s content.

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

Sidebar

Related Questions

I have an a Java Android app that calls different activities. I thought this
Beginner in Android development. My code crashes. I have made a simple Java method
Ok In an android vebview I have a java method. Is it possible that
It seems the java.net.NetworkInterface implementation of android does not have a byte[] getHardwareAddress() method
I have to admit that I'm new to Java and Android. db4o seems to
I have an OpenCV Android app. Most of its code is in Java but
I have a Java handler code which Im using in android to run a
What I'm doing exactly is this: I have a class Welcome that calls another
I have a basic database that calls on string into the database(well supposed to).
I have a java webservice, with some method. The webservice methods are in this

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.