这是一个基于android-php-mysql连接的简单项目,使用xamp server.Here iam尝试更新查询,并在服务器数据库中成功更新,并获得php响应授予,但如果我的程序中的条件是不工作,我该怎么办?请帮帮我..这是我的代码!! 提前谢谢你
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();
}
}
});
答案 0 :(得分:0)
试试这个..希望它有效
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);
}
答案 1 :(得分:0)
请初始化 public static String response =“”;
response = httpclient.execute(httppost,responseHandler);