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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T18:33:30+00:00 2026-05-23T18:33:30+00:00

I was playing around with code that I found here . The I can

  • 0

I was playing around with code that I found here. The I can only get my database to return a null json object. Here is my code.

public class TableTalkSplash extends Activity {
    private InputStream is;

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

      String result = "";
      InputStream is = null;
      //the year data to send
      ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
      nameValuePairs.add(new BasicNameValuePair("row_id","1"));

      //http post
      try{
              HttpClient httpclient = new DefaultHttpClient();
              HttpPost httppost = new HttpPost("http://mywebsite.com/myscript.php");
              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,"iso-8859-1"),8);
              StringBuilder sb = new StringBuilder();
              String line = null;
              while ((line = reader.readLine()) != null) {
                      sb.append(line + "\n");
              }
              is.close();

              result=sb.toString();
              System.out.println(result); // this is printing "null" to the console
      }catch(Exception e){
              Log.e("log_tag", "Error converting result "+e.toString());
      }

      //parse json data
      try{
              JSONArray jArray = new JSONArray(result);
              for(int i=0;i<jArray.length();i++){
                      JSONObject json_data = jArray.getJSONObject(i);
                      Log.i("log_tag","id: "+json_data.getInt("id")+
                              ", name: "+json_data.getString("name")+
                              ", sex: "+json_data.getInt("sex")+
                              ", birthyear: "+json_data.getInt("birthyear")
                      );
              }

      }catch(JSONException e){
              Log.e("log_tag", "Error parsing data "+e.toString()); //exception is being caught here
      }
    }
}

Here is my php script.

<?php
mysql_connect("host","username","password");
mysql_select_db("mydb");

$q=mysql_query("SELECT * FROM dinner_info WHERE row_id ='".$_REQUEST['row_id']."'");
while($e=mysql_fetch_assoc($q))
        $output[]=$e;

print(json_encode($output));

mysql_close();
?>

I have an apache webserver currently running a website and the .php file is in the same directory as the index.html file. I have a mySQL database that is running on the same box as the apache server. I really know very little about databases, but I do know that when I run SELECT * FROM dinner_info WHERE row_id = 1; It returns the correct information. So I am guessing my error is in the php. I’ve tried to replace the “host” with localhost and “username” with my username and “password” with my password. Any Ideas? if you need more information let me know! Thanks everyone.

  • 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-23T18:33:30+00:00Added an answer on May 23, 2026 at 6:33 pm

    I’m guessing the db connection or query is failing try this to help with the debugging:

    <?php
    
    error_reporting(-1);
    ini_set("display_errors", 1);
    
    mysql_connect("host","username","password") or die('Could not connect: ' . mysql_error());;
    mysql_select_db("mydb");
    
    $query = "SELECT * FROM dinner_info WHERE row_id ='".mysql_real_escape_string($_REQUEST['row_id'])."'"
    
    $q=mysql_query($query);
    
    if (!$q) {
        $message  = 'Invalid query: ' . mysql_error() . "\n";
        $message .= 'Whole query: ' . $query;
        die($message);
    }
    
    while($e=mysql_fetch_assoc($q))
            $output[]=$e;
    
    print(json_encode($output));
    
    mysql_close();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I was playing around with some JavaScript code and found that when I took
I am playing around with a code example i found here about 'tree menu'
Here is some C++ code I'm playing around with: #include <iostream> #include <vector> #define
I was playing around with anonymous subclasses and I found a problem that I
I’ve been playing around with searching text in big lists and found that using
I'm playing around with OpenGL and I'm finding myself writing code that I feel
I'm playing around with template specialization, and I've found an issue I can't seem
I am playing around with the fastCGI application found here . The following comment
I have been playing around with haskell and I found out that if I
While playing around with as' vector.sort() I found out that it behaves normally in

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.