Php 如果程序内的条件不工作
这是一个使用xamp服务器的基于android php mysql连接的简单项目。在这里,我试图更新查询,并在服务器数据库中成功更新查询,并获得php响应,但如果我的程序中的条件不起作用,我该怎么办??请帮帮我…这是我的密码!! 先谢谢你Php 如果程序内的条件不工作,php,android,Php,Android,这是一个使用xamp服务器的基于android php mysql连接的简单项目。在这里,我试图更新查询,并在服务器数据库中成功更新查询,并获得php响应,但如果我的程序中的条件不起作用,我该怎么办??请帮帮我…这是我的密码!! 先谢谢你 btt.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { try{ httpcl
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();
}
}
});
btt.setOnClickListener(新视图.OnClickListener(){
@凌驾
公共void onClick(视图v){
试一试{
httpclient=新的DefaultHttpClient();
httppost=新的httppost(“http://192.168.0.45/doctorphp/status.php“”;//请确保url正确无误。
//添加您的数据
nameValuePairs=新的ArrayList(1);
//发布时始终使用相同的变量名,即android端变量名和php端变量名应相似,
nameValuePairs.add(新的BasicNameValuePairs(“日期”,Datetxt.getText().toString().trim());//$Edittext\u值=$\u POST['Edittext\u值'];
setEntity(新的UrlEncodedFormEntity(nameValuePairs));
ResponseHandler ResponseHandler=新BasicResponseHandler();
最终字符串响应=httpclient.execute(httppost,responseHandler);
System.out.println(“响应:+Response”);
runOnUiThread(新的Runnable(){
公开募捐{
setText(“来自PHP的响应:+Response”);
} });
if(响应同等信号情况(“已批准”)){
runOnUiThread(新的Runnable(){
公开募捐{
Toast.makeText(UserPage.this,“成功授予”,Toast.LENGTH_SHORT.show();
}
});
Intent Intent=新的Intent(UserPage.this,token.class);
星触觉(意向);
}
否则{
showarert();
}
}
捕获(例外e){
System.out.println(“异常:+e.getMessage());
Toast.makeText(getApplicationContext(),“错误:+e.toString(),Toast.LENGTH_LONG).show();
}
}
});
试试这个……希望它能奏效
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);
}
请初始化
公共静态字符串响应=”
response=httpclient.execute(httppost,responseHandler) 你调试过它了吗?如果没有,你会得到什么反应?对不起…它不工作,如果不执行if block,它将直接执行我程序的else block,那么您应该首先检查您的响应。@AshikAshok请接受为ans n upvote,如果这个ans对您有帮助,buddy:)。@SweetWisher我想这对字符串比较不起作用。。我的条件是rite,我想:)