I am trying to access a database through a simple PHP code. But the constraints are that it is a remote database, accessed by a remote server from a real device.
here is a snippet of the code:-
ArrayList<NameValuePair> postParameters = new ArrayList<NameValuePair>();
postParameters.add(new BasicNameValuePair("username", un.getText().toString()));
postParameters.add(new BasicNameValuePair("password", pw.getText().toString()));
String response = null;
try {
response = CustomHttpClient.executeHttpPost("http://WebsiteName.com/check.php", postParameters);
String res=response.toString();
res= res.replaceAll("\\s+","");
if(res.equals("1"))
error.setText("Correct Username or Password");
else
error.setText("Sorry!! Incorrect Username or Password");
} catch (Exception e) {
un.setText(e.toString());
}
The PHP is here. Most probably there is no problem with the PHP code because it works locally.
One of the most important things I want to clarify is where to keep the PHP code in the server. I have it directly under the root directory. When i execute it from the browser (say by typing website.com/check.php), i get the required response. Unfortunately many people who have given a tutorial on this, has mentioned about local server and local database more than remote ones. Is there something more I should do for getting it done with a real device?
PS: The app works fine when connected to an emulator and local database with local webserver.
===UPDATE===
I am pretty sure that the phone is not contacting the web server. I verified by making the webserver give a positive response always, which also failed. Any hints on where I should look at? I can't think of anything other than the online server...which is working (when checked from browser). Any way of cross checking it? Thanks.