This is a simple project based on android-php-mysql connection using xamp server.Here iam trying to update the query,and its updating successfully in server database,and getting php respond as granted,but if condition in my program is not working,what will i do?? please help me..Here is my code!! thank you in advance
btt.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
try{
httpclient=new DefaultHttpClient();
httppost= new HttpPost("http://192.168.0.45/doctorphp/status.php"); // make sure the url is correct.
//add your data
nameValuePairs = new ArrayList<NameValuePair>(1);
// 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("date",Datetxt.getText().toString().trim())); // $Edittext_value = $_POST['Edittext_value'];
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
ResponseHandler<String> responseHandler = new BasicResponseHandler();
final String response = httpclient.execute(httppost, responseHandler);
System.out.println("Response : " + response);
runOnUiThread(new Runnable() {
public void run() {
tvView.setText("Response from PHP : " + response);
} });
if(response.equalsIgnoreCase("Granted")){
runOnUiThread(new Runnable() {
public void run() {
Toast.makeText(UserPage.this,"Granted successfully", Toast.LENGTH_SHORT).show();
}
});
Intent intent=new Intent(UserPage.this, token.class);
startActivity(intent);
}
else{
showAlert();
}
}
catch(Exception e){
System.out.println("Exception : " + e.getMessage());
Toast.makeText(getApplicationContext(),"Error:"+e.toString(), Toast.LENGTH_LONG).show();
}
}
});
try this..hope it works
if(response.toString().trim().equalsIgnoreCase("Granted")){
runOnUiThread(new Runnable() {
public void run() {
Toast.makeText(UserPage.this,"Granted successfully", Toast.LENGTH_SHORT).show();
}
});
Intent intent=new Intent(UserPage.this, token.class);
startActivity(intent);
}
please initialize public static String response="";
response = httpclient.execute(httppost, responseHandler);