以下代码是我为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();
}
}
的login.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..";
}
?>
答案 0 :(得分:3)
尝试使用result.contains("Login Success")
代替result.equals()
作为PHP,我最后会返回一些符号,例如特定于服务器的回车符号。
答案 1 :(得分:1)
试试这个
result.contains("Login Success"){ // contains will check the availability of Login Success.
//Your Code
}
而不是
if(result.equals("Login Success")){ // check the Complete String .
//Your Code
}
答案 2 :(得分:0)
我认为你应该检查&#34;登录成功&#34;而不是&#34;注册成功......&#34;
并且在PHP端也使用boolean值作为返回类型。 喜欢状态真/假。
不要使用字符串作为状态。
在PHP方面:
echo true;
else
echo false;
就像那样。
在Android方面:
if(result)
{
Toast.makeText(ctx, "Login Success", Toast.LENGTH_LONG).show();
} else {
...
}