0

I am creating application where the user enters data to search and then application sends it to server and then server sends search result back to the client.

I am getting error with i am not able to understand what it means.

here is my networking code from there application and here is link to full code

 public class GetDatafromDB_Searchresult {

        public String getDataFromDB() {


            try {

                httpclient = new DefaultHttpClient();
                httppost = new HttpPost("http://192.168.0.106/test/search1.php"); // make sure the url is correct.
                //add your data
                nameValuePairs = new ArrayList<NameValuePair>(2);
                // Always use the same variable name for posting i.e the android side variable name and php side variable name should be similar,
                nameValuePairs.add(new BasicNameValuePair("carat1", strcolor1.toString().trim()));
                nameValuePairs.add(new BasicNameValuePair("carat2", strcolor2.toString().trim()));
                nameValuePairs.add(new BasicNameValuePair("color1", strclarity1.toString().trim()));
                nameValuePairs.add(new BasicNameValuePair("color2", strclarity2.toString().trim()));
                nameValuePairs.add(new BasicNameValuePair("cut1", strcut1.toString().trim()));
                nameValuePairs.add(new BasicNameValuePair("cut2", strcut2.toString().trim()));
                nameValuePairs.add(new BasicNameValuePair("shape1", strshape1.toString().trim()));
                nameValuePairs.add(new BasicNameValuePair("shape2", strshape2.toString().trim()));
                nameValuePairs.add(new BasicNameValuePair("stones", strstone.toString().trim()));


                // $Edittext_value = $_POST['Edittext_value'];

                    httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
                    //Execute HTTP Post Request
                    response = httpclient.execute(httppost);
                HttpEntity entity= response.getEntity();
                {
                    if(entity!=null)
                    {
                        entity.consumeContent();
                    }
                }

                ResponseHandler<String> responseHandler = new BasicResponseHandler();
                final String response1 = httpclient.execute(httppost, responseHandler);
                System.out.println("Response : " + response1);

            } catch (Exception e) {
                e.printStackTrace();
                System.out.println("Exception : " + e.getMessage());

            }


            return response1;

        }
    }

here is my server side code

  <?php
$hostname_localhost ="localhost";
$database_localhost ="testdb";
$username_localhost ="root";
$password_localhost ="";
$localhost = mysql_connect($hostname_localhost,$username_localhost,$password_localhost)
or
trigger_error(mysql_error(),E_USER_ERROR);

 mysql_select_db($database_localhost, $localhost);

$carat1 = $_POST['carat1'];
$carat2 = $_POST['carat2'];
$color1 = $_POST['color1'];
$color2 = $_POST['color2'];
$cut1 = $_POST['cut1'];
$cut2 = $_POST['cut2'];
$shape1 = $_POST['shape1'];
$shape2 = $_POST['shape2'];
$stones = $_POST['stones'];


$query_search ="Select * from search1 where 
carats = $carat1 and carats = $carat2 and 
color = '$color1' or color =  '$color2' and 
 cut = '$cut1' or cut = '$cut2' and 
 shape = '$shape1' or shape = '$shape2' and 
 stone ='$stones'";

$query_exec = mysql_query($query_search) or die(mysql_error());


    while($row=mysql_fetch_assoc($query_exec))
            $json_output[]=$row;
      echo json_encode($json_output);

    mysql_close(); 
?>

here is my error from logcat

06-03 14:35:31.269  18943-19053/com.diamond.traders W/System.err﹕ org.apache.http.client.HttpResponseException: Not Found
06-03 14:35:31.269  18943-19053/com.diamond.traders W/System.err﹕ at org.apache.http.impl.client.BasicResponseHandler.handleResponse(BasicResponseHandler.java:71)
06-03 14:35:31.269  18943-19053/com.diamond.traders W/System.err﹕ at org.apache.http.impl.client.BasicResponseHandler.handleResponse(BasicResponseHandler.java:59)
06-03 14:35:31.269  18943-19053/com.diamond.traders W/System.err﹕ at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:657)
06-03 14:35:31.269  18943-19053/com.diamond.traders W/System.err﹕ at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:627)
06-03 14:35:31.269  18943-19053/com.diamond.traders W/System.err﹕ at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:616)
06-03 14:35:31.269  18943-19053/com.diamond.traders W/System.err﹕ at com.diamond.traders.Search_result$GetDatafromDB_Searchresult.getDataFromDB(Search_result.java:692)
06-03 14:35:31.269  18943-19053/com.diamond.traders W/System.err﹕ at com.diamond.traders.Search_result$1.run(Search_result.java:88)
06-03 14:35:31.269  18943-19053/com.diamond.traders W/System.err﹕ at java.lang.Thread.run(Thread.java:841)
06-03 14:35:31.269  18943-19053/com.diamond.traders I/System.out﹕ Exception : Not Found
06-03 14:35:31.269  18943-18943/com.diamond.traders E/log_tag﹕ Error parsing data org.json.JSONException: End of input at character 0 of

1 Answer 1

2

I'm not sure but I suggest to you firstable to replace this line

nameValuePairs = new ArrayList<NameValuePair>(2);

by

nameValuePairs = new ArrayList<NameValuePair>();

And in your web service, you have to work with POST not GET.

Sign up to request clarification or add additional context in comments.

5 Comments

i did make change, both the changes you told me, still there is no change in the error and application is still not working.
also i need to ask one question and that is, what is the use of nameValuePairs = new ArrayList<NameValuePair>(2); especially what is the us of "(2)".
You initially set the size of the ArrayList to 2. But, it can be extended up to what ever you add to it. So your problem is obvsiouly not here. Did you change the _GET in you script PHP with _POST ?
Looking for POST rather than GET on the server side fixed this same problem for me. I think this answer should be the accepted one, though I don't care for the ArrayList lesson.
That first suggestion does absolutely nothing.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.