I am new to Android and am currently trying to connect Android to a database through PHP. I can easily connect the PHP script to my database but I cannot get Android to talk to the PHP script. I have tried multiple examples - http://www.androidaspect.com/2013/05/how-to-connect-android-with-php.html - but cannot seem to get it to work. If I could get Android to simply receive a message saying 'hello' from the PHP script, I would easily be able to finish my work but I cannot. I have been told to do things such as use ASync but quite frankly that just makes this so much more complicated. Any help would be appreciated in getting my Android side to talk to my PHP side. Thank you very much in advance.
I've deleted the actual code that I've tried but one tutorial is linked above and the other had me try this -
ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
nameValuePairs.add(new BasicNameValuePair("rec","mar"));
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://10.0.2.2/select.php");
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
is = entity.getContent();
BufferedReader reader = new BufferedReader
(new InputStreamReader(is,"iso-8859-1"),8);
StringBuilder sb = new StringBuilder();
while ((line = reader.readLine()) != null)
{
sb.append(line + "
");
}
is.close();
result = sb.toString();
JSONObject json_data = new JSONObject(result);
name=(json_data.getString("name"));
Toast.makeText(getBaseContext(), "Name : "+name,
Toast.LENGTH_SHORT).show();