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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T22:20:40+00:00 2026-05-24T22:20:40+00:00

I have written a code in android as as well as in php..while sending

  • 0

I have written a code in android as as well as in php..while sending data from emulator and php in localhost it is working fine..but when i change the server to http://www.xxx.com/test.php, it is sending a null value from a real android device and null value is saving in the mysql database..

What might be the problem?

Thanks in advance..

My Code:
InputStream is;

HttpPost httppost = new HttpPost("http://xxx.com/usercheck.php");
HttpClient httpclient = new DefaultHttpClient();

JSONObject json = new JSONObject(); 


    try {

        json.put("username",txtusername.getText().toString()); 
        json.put("password",txtpassword.getText().toString());           

        List<NameValuePair> parameters = new ArrayList<NameValuePair>(2);
        parameters.add(new BasicNameValuePair("userpwd_value",json.toString()));

        httppost.setEntity(new UrlEncodedFormEntity(parameters));  

        ResponseHandler<String> responseHandler = new BasicResponseHandler();
        String response = httpclient.execute(httppost, responseHandler);
        //This is the response from a php application
        String reverseString = response;
            Toast.makeText(this, "response" + reverseString, Toast.LENGTH_LONG).show();
        } catch (ClientProtocolException e) {
            Toast.makeText(this, "CPE response " + e.toString(), Toast.LENGTH_LONG).show();
        // TODO Auto-generated catch block
        } catch (IOException e) {
            Toast.makeText(this, "IOE response " + e.toString(), Toast.LENGTH_LONG).show();
        // TODO Auto-generated catch block
        } catch (JSONException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

PHP Code:

<?php
  require_once('config.php');
    //$data = file_get_contents('php://input');//tried this also
   $a=$_POST['userpwd_value']; //accesing value from android
   $b=json_decode($a); //decoding android value using JSON

  $username=$b->{'username'}; //assigning username from android to a variable  
  $password=$b->{'password'};//assigning password from android to a variable  

  //echo $username.$password;
  if($username=="" || $password=="")
    $output[]=array("value"=>"false");
  else
    {   

      $check = mysql_query("select userid,password from xxx where userid='".$username."'");

      $row = mysql_fetch_array($check);

      if($row['userid']==$username && $row['password']==$password)
        {
          $output[]=array("value"=>"true");
        } 
      else 
      { 
          $output[]=array("value"=>"false");
      }
      print(json_encode($output));
   }  
 ?>
  • 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-24T22:20:41+00:00Added an answer on May 24, 2026 at 10:20 pm

    In my case I can do this way,

    HttpClient httpclient = new DefaultHttpClient();
    HttpPost httppost = new HttpPost(url);
    
    httppost.addHeader("Content-Type", "application/x-www-form-urlencoded");
    httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs,HTTP.UTF_8));
            // Execute HTTP Post Request
    HttpResponse response = httpclient.execute(httppost);
            // get response entity
    HttpEntity entity = response.getEntity();
    
            // convert entity response to string
     if (entity != null) {
    
        InputStream is = entity.getContent();
        // convert stream to string
        result = convertStreamToString(is); 
        result = result.replace("\n", "");
        }
    

    Hope this will help you.. Thnx.

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

Sidebar

Related Questions

I have code written for Android 2.2 that is supposed to parse xml from
I have written jQuery code, in files Main.html and ajax.php . The ajax.php file
I am trying to use custom font in android. I have written java code
I have written the code to select a folder from the SDCard and its
I have written a small android app that grabs some data and displays it
hi i am new developer on android i have written code for display simple
I have written code that automatically creates CSS sprites based on the IMG tags
I have written code that opens 16 figures at once. Currently, they all open
I have written code in Java to access web cam,and to save image... I
I have written some code in my VB.NET application to send an HTML e-mail

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.