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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T17:11:26+00:00 2026-06-04T17:11:26+00:00

Probably problem with the php file which contains the following code: <?php mysql_connect(localhost,root,); mysql_select_db(deal);

  • 0

Probably problem with the php file which contains the following code:

    <?php
mysql_connect("localhost","root","");
mysql_select_db("deal");
$sql=mysql_query("select * from CITY");
while($row=mysql_fetch_assoc($sql))
$output[]=$row;
print(json_encode($output));
mysql_close();
?>

simple code to retrieve all cities in db.
I located this file in: C:\Program Files\EasyPHP-5.3.9\www\city.php

the java code is very simple, connecting and showing the query results:

package com.udios.mysql;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.app.Activity;
import android.net.ParseException;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Toast;

public class MySQLActivity extends Activity {

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    }

    public void onTestClick(View view) {
        /*Toast.makeText(MySQLActivity.this, "Test Pressed", Toast.LENGTH_SHORT)
                .show();*/

        this.runOnUiThread(new Runnable() {

            @Override
            public void run() {
                String result = null;

                JSONArray jArray;
                InputStream is = null;
                StringBuilder sb = null;
                try {
                    ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
                    HttpClient httpclient = new DefaultHttpClient();
                    HttpPost httppost = new HttpPost("http://127.0.0.1/city.php");
                    httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
                    HttpResponse response = httpclient.execute(httppost);
                    HttpEntity entity = response.getEntity();
                    is = entity.getContent();

                    BufferedReader reader = new BufferedReader(
                            new InputStreamReader(is, "iso-8859-1"), 8);
                    sb = new StringBuilder();
                    sb.append(reader.readLine() + "\n");

                    String line = "0";
                    while ((line = reader.readLine()) != null) {
                        sb.append(line + "\n");
                    }
                    is.close();
                    result = sb.toString();

                    int ct_id;
                    String ct_name;
                    Toast.makeText(getBaseContext(), "result is: "+result,
                            100).show();
                    jArray = new JSONArray(result);
                    JSONObject json_data = null;
                    for (int i = 0; i < jArray.length(); i++) {
                        json_data = jArray.getJSONObject(i);
                        ct_id = json_data.getInt("CITY_ID");
                        ct_name = json_data.getString("CITY_NAME");


                        Toast.makeText(getBaseContext(), Integer.toString(ct_id)+" : " +  ct_name , 
                                Toast.LENGTH_LONG).show();

                    }
                } catch (JSONException e1) {
                    Toast.makeText(getBaseContext(), "No City Found",
                            Toast.LENGTH_LONG).show();
                } catch (ParseException e1) {
                    e1.printStackTrace();
                } catch (Exception e1) {
                    e1.printStackTrace();
                }

            }
        });

    }
}

When i’m trying to access directly in browser to:

I gets:
Notice: Undefined variable: output in C:\Program Files\EasyPHP-5.3.9\www\city.php on line 7
null

i’m debugging in android and this line throws exception: (last catch)

HttpPost httppost = new HttpPost("http://127.0.0.1/city.php");

if i change it to 10.0.2.2 it throws exception in this line:

HttpResponse response = httpclient.execute(httppost);

i’ve really tried all combination, Can someone please help me?
thank you very much
udi

  • 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-04T17:11:28+00:00Added an answer on June 4, 2026 at 5:11 pm

    The first time you add a row to $output it is undefined.

    Add this before the while loop in your PHP code.

    $output = array();
    

    You also need to connect 10.0.2.2 if you are running on the emulator, or your local IP on a real device (make sure the device is connected to your network via WiFi).

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

Sidebar

Related Questions

I need to override a function in this file: app/code/core/Mage/Core/functions.php The problem is that
this is probably an include problem, i get these errors all over the code,
Most of you probably know the following problem: You edit an HTML, view the
I've got a problem which is probably very easy to solve but I can't
I have a 9000-line PHP file which consists of about 30 discrete areas, navigated
My problem has probably been asked, but all the ones I've been searching for
This is probably a trivial problem for most of you... Below is a stored
Problem : This is a probably a very basic question, but how do I
i've a strange problem with JS (probably a noob bug), but i'm stuck with
well i have most probably an extremly stupid problem but could not figure it

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.