In my Android:
String cat_id = getIntent().getExtras().getString("category_id");
ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
nameValuePairs.add(new BasicNameValuePair("cat_id", cat_id));
try {
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(
"http://www.---.com/items.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());
}
In my PHP:
// editing out DB connections which have been verified to work
<?php
$sql=mysql_query("SELECT * FROM items WHERE cat_id = '".$_REQUEST['cat_id']."'");
while($row=mysql_fetch_assoc($sql))
$output[]=$row;
print(json_encode($output));
mysql_close();
?>
So my issues is that It is returning nothing (in the JSON result part — a Toast says “No item is found”). Is my code correct, the way I am passing parameters from Android to PHP?
I figured out what was and it was nobody’s fault for not answering.
The issue started before Java passed on to PHP. It was a bundle that passed into the Java Activity in question. I had a simple mistake involving using an incorrect primitive which in turn caused a null to be passed in through a bundle.
The null continued down the path and landed in the PHP part. So the code shown above is actually correct.