以下代码是我出于 Intent 而添加的代码,结果是从我的login.php 返回的内容。但它无法比较成功与否。在任何情况下它都不会进入 if 循环。但它在警报对话框中显示“登录成功”。
@Override
protected void onPostExecute(String result) {
if(result.equals("Login Success")){
Intent intent = new Intent();
intent.setClassName("com.example.soumya.attendance","com.example.soumya.attendance.LoginActivity");
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
ctx.startActivity(intent);}
else{
alertDialog.setMessage("No Condition Matched..");
alertDialog.show();
}
}
登录.php
<?php
require "init.php";
$uname = $_POST["login_name"];
$password = $_POST["login_pass"];
$sql_query = "select name from students where uname like '$uname' and password like '$password';";
$result = mysqli_query($con,$sql_query);
if(mysqli_num_rows($result) >0 )
{
$row = mysqli_fetch_assoc($result);
$name =$row["name"];
echo "Login Success";
}
else
{
echo "Login Failed.......Try Again..";
}
?>
最佳答案
尝试使用 result.contains("Login Success")
而不是 result.equals()
作为 PHP 我最后返回一些符号,例如服务器特定的回车符左右。
关于java - onPostexecute 中的字符串比较不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36615598/