Tuesday, 13 August 2013

How to Post variables to a PHP script from Android, execute query, then return an array using different Post variables into a Listview?

How to Post variables to a PHP script from Android, execute query, then
return an array using different Post variables into a Listview?

I am able to insert information into the database and get information from
the database. Where I'm having a problem is posting variables that can be
read by the php and at the same time receiving information from the query.
This is for a search filter, so the first set of variables are used to
define the query, then the other post variables are used to read off the
url. Here is the code that I've used to post variables:
// Create a new HttpClient and Post Header
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://www.yourdomain.com/post.php");
try {
// Add your data
List nameValuePairs = new ArrayList(1);
nameValuePairs.add(new BasicNameValuePair("data1", "dataValue"));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
// Execute HTTP Post Request
HttpResponse response = httpclient.execute(httppost);
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
} catch (IOException e) {
// TODO Auto-generated catch block
}
The main problem is that the specific query is not recognized and
everything in the table is returned.
Anything unclear or questions just comment. Thanks

No comments:

Post a Comment