PHP脚本服务器端没有将任何内容返回给Android应用程序

I'm programming a client-server application for Android where the application sends a POST to a php-script server side. This script search a database and returns the results. However I'm not getting it to work. The communication between client and server is json formatted.

This is the functions in the android activity. The second function is a copy-paste which I can take no credit for and which I found on the internetz:

private void testDB(){
    //Creating a json-representation of my query

    JSONObject query = new JSONObject();

    try {
        query.put("author", "SomeAuthor");
        query.put("title", "SomeTitle");

    } catch (JSONException e1) {
        e1.printStackTrace();
    }

    String json = query.toString();

    // Create a new HttpClient and Post Header
    HttpClient httpclient = new DefaultHttpClient();
    HttpPost httppost = new HttpPost("http://myserver.com/search_books.php");


    try {           
        List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);  
        nameValuePairs.add(new BasicNameValuePair("jsondata", json));  
        httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
        HttpResponse response = httpclient.execute(httppost);

        InputStream in = response.getEntity().getContent();

        String results = convertStreamToString(in);

        Toast.makeText(getApplicationContext(), results, Toast.LENGTH_LONG).show();

    } catch (ClientProtocolException e) {
        System.out.println("ERROR (ClientProtocolException): " + e.toString());
    } catch (IOException e) {
        System.out.println("ERROR (IOException): " + e.toString());     
    } 

}

private String convertStreamToString(InputStream is) {
    /*
     * To convert the InputStream to String we use the BufferedReader.readLine()
     * method. We iterate until the BufferedReader return null which means
     * there's no more data to read. Each line will appended to a StringBuilder
     * and returned as String.
     */
    BufferedReader reader = new BufferedReader(new InputStreamReader(is));
    StringBuilder sb = new StringBuilder();

    String line = null;
    try {
        while ((line = reader.readLine()) != null) {
            sb.append(line + "
");
        }

    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        try {
            is.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    return sb.toString();
}

And this is the php-script:

<?php
//Get the information from the request (POST)
$jsonInput = $_POST['jsondata'];
$decoded = json_decode($jsonInput,true);

//Connect to the database
$connection = mysql_connect(localhost, username, password);

if (!$connection) {
    die("Could not connect to db: " . mysql_error());   
}

//Select the database to be used
mysql_select_db("muffin_books", $connection) or die(mysql_error());

//Construct the query
$sql = "SELECT * FROM Books WHERE author='" . $decoded['author'] . "' AND title='" . $decoded['title'] . "'";

//Make the query to the database with the connection
$query_results = mysql_query($sql, $connection); 

//If no results were returned
if (!$query_results) {
    die("Could not connect to db: ", mysql_error());
}

//Get the array from the results
$info = mysql_fetch_array($query_results, MYSQL_ASSOC);

//Return the data encoded in json
echo json_encode($info);

//Disconnect database
mysql_close($connection);
?>

The problem is that the Toast just comes up empty. I am 100% sure that the row exists in the database. myserver.com is not my actual server, in my file it says something else here. username and password are also customized in my code.

Thanks in advance!

since you are sending strig to the server i think you need to modify your sql query as

$sql = "SELECT * FROM Books WHERE author=" . $decoded['author'] . " AND title=" .      $decoded['title'] . "";