doushao5047 2015-11-01 16:34
浏览 43
已采纳

从php webservice获得结果“成功”时打开另一个活动但是没有用,android

I have used a php webservice where i am matching login credentials if true i pass "success", if false i pass "failure".

and In java code, i am matching result data and apply condition when will open another activity and when will show a toast for wrong credentials.

But when i put either wrong or right credentials it will always open another activity. never show a toast

So please help me , what should I do ?

my code

 @Override
    protected void onPostExecute(String result) {
        String str = result.trim();
        if(str=="success") {
            startActivity(new Intent(Login.this,MainActivity.class));
        }
        else{
            Toast.makeText(Login.this, "Either Username or Password is not correct", Toast.LENGTH_SHORT).show();
        }
        dialog.dismiss();
    }

my php code

$sql = "select * from master_login_tbl where user_id = '$user' or email='$user' and password = '$pass' ";
$result = mysql_query($sql);
$check = mysql_fetch_array($result);
$num_of_rows = mysql_num_rows($result);
if($num_of_rows > 0){echo "success";}else{echo 'failure';}
  • 写回答

1条回答 默认 最新

  • drxdai15012937753 2015-11-01 17:20
    关注

    You need to use str.equals("success"), comparing strings in Java with == does not work because you compare the objects and not the string.

    You can also use equalsIgnoreCase("success)", which, as the name suggests, ignores any upper or lower case differences.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?