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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T09:22:46+00:00 2026-06-01T09:22:46+00:00

I am trying to retrieve specific data from my MySQL database by passing the

  • 0

I am trying to retrieve specific data from my MySQL database by passing the value of the parameter from Android and then read this value in a PHP script in the query in order to return the data.

When I run the application an error parsing data exception occurs because the returned result value is null?

Why the result is null? Is the error from the PHP script or from my java code ?

please help me

Thanks in advance!

city.php:

  <?php
     mysql_connect("localhost","username","password");
     mysql_select_db("Countries");
     $sql=mysql_query("select  City_Population  from City where Name= "'.$_REQUEST['Name']."'");
     while($row=mysql_fetch_assoc($sql))
     $output[]=$row;
      print(json_encode($output));
      mysql_close();
        ?>

Blockquote

java class:

       public class ConnectActivity extends ListActivity {

           String add="http://10.0.2.2/city.php";
           public void onCreate(Bundle savedInstanceState) {
           super.onCreate(savedInstanceState);
           setContentView(R.layout.main);

            new Connect().execute();

         }

  private class Connect extends AsyncTask<Void,Void,String>
   {     
             private  String result = "";
             private  InputStream is=null;
            private  String city_name="London";
           protected String doInBackground(Void... params) {
            try
          {
                  ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
                 nameValuePairs.add(new BasicNameValuePair("Name",city_name));
                 HttpClient httpclient = new DefaultHttpClient();
                HttpPost httppost = new HttpPost(add);
                httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
               HttpResponse response = httpclient.execute(httppost);
               HttpEntity entity = response.getEntity();
              is = entity.getContent();
                 }
        catch(Exception e)
           {
               Log.e("log_tag", "Error in http connection "+e.toString());
                 }


           //convert response to string
    try{
    BufferedReader reader = new BufferedReader(new InputStreamReader(is,"utf-8"),8);
    StringBuilder sb = new StringBuilder();
     String line = null;
     while ((line = reader.readLine()) != null) {
      sb.append(line + "\n");
       }
        is.close();
        result=sb.toString();
           }
          catch(Exception e){
           Log.e("log_tag", "Error converting result "+e.toString());
               }


          return result;
          }
       protected  void onPostExecute(String  result){

        try{
            JSONArray jArray = new JSONArray( result);
            JSONObject json_data=null;
            for(int i=0;i<jArray.length();i++)
            {
                json_data = jArray.getJSONObject(i);
                int  population=json_data.getInt("City_Population");

              TextView City_Name =(TextView)findViewById(R.id.city_name);
                                                                           TextView  City_population=(TextView)findViewById(R.id.city_pop);
                            City_Name.setText(json_data.getString(city_name));
                                                                          City_population.setText(population+"  " );
            }
            }
            catch(JSONException e){
            Log.e("log_tag", "Error parsing data "+e.toString());
            }


                     }
                                                                  }

                                                    }
  • 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-01T09:22:48+00:00Added an answer on June 1, 2026 at 9:22 am
         <?php
             $name=$_POST['NAME'];               
             mysql_connect("localhost","username","password");
             mysql_select_db("Countries");
             $sql=mysql_query("select  City_Population as citypop  from City where Name='$name' ");
             while($row=mysql_fetch_assoc($sql))
              $output=$row['citypop'];
            print(json_encode($output));
             mysql_close();
             ?>
    

    You try this sure it will work .

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

Sidebar

Related Questions

Iam trying to retrieve data from mysql database into stylesheet.php but it is not
I'm trying to retrieve data from an SQL Server 2000 server, and place into
I'm trying to retrieve note titles from a specific notebook whenever the user clicks
I'm trying to retrieve specific tags with their content out of an xhtml document,
I am trying retrieve user name from the code through graph api, the below
I'm trying to retrieve a file from a server using SFTP (as opposed to
I'm trying to retrieve an XML stream from a URL. For most URLs my
I'm new to MyBatis and my project requires me to read the data from
I'm trying to retrieve link text from an HTML file. Each of the link
I'm trying to extract data from an xml file. A sample of my code

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.