这是我的PHP代码,当我想做一个自定义方法if(字符串等于成功)但它不起作用。如果此方法返回一个字符串值的响应。如果响应成功,我想做一些方法
<?php
define('HOST','mysql.hostinger.in');
define('USER','example');
define('PASS','example');
define('DB','example');
$con = mysqli_connect(HOST,USER,PASS,DB);
$username = $_POST['PHONENO'];
$password = $_POST['PASSWORD'];
$sql = "SELECT * FROM Prago WHERE PHONENO='$username' and PASSWORD='$password'";
$res = mysqli_query($con,$sql);
$check = mysqli_fetch_array($res);
if(isset($check)){
echo 'success';
}else{
echo 'failure';
}
mysqli_close($con);
?>
我的凌空字符串请求类
StringRequest stringRequest=new StringRequest(Request.Method.POST, REGISTER_URL, new Response.Listener<String>() {
@Override
public void onResponse(String response) {
if(response.equals("success")){
Toast.makeText(getApplicationContext(),"DONE",Toast.LENGTH_SHORT).show();
}
else
{
Toast.makeText(getApplicationContext(),"check username and password",Toast.LENGTH_SHORT).show();
}
callback.onSuccess(response);
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(getApplication(),"error in volley",Toast.LENGTH_SHORT).show();
}
}){
@Override
protected Map<String, String> getParams() throws AuthFailureError {
Map<String,String> map=new HashMap<>();
map.put("PHONENO",Number);
map.put("PASSWORD",Pass);
return map;
}
};
VolleySingleton.getInstance().addToRequestQueue(stringRequest);
}
答案 0 :(得分:0)
正如@greenapps在评论中所指出的那样,将.equals()
更改为.contains()
是有效的,因为在我的情况下,回复是双引号,所以&#34;成功&#34;!=成功但是&#34;成功&#34;包含成功
答案 1 :(得分:0)
首先检查您通过调试收到的回复,或者只是简单地祝贺您的回复