Android使用PHP和mysql登录 [英] Android login using PHP and mysql

查看:109
本文介绍了Android使用PHP和mysql登录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用php和mysql开发一个Android应用程序。此登录有一个限制,只有活动用户才能登录。在mysql表中,active active分别设置为1或0表示活动和非活动。这里的问题是当active的值设置为1时,它显示为不活动。这是我下面的代码



我尝试过:



Android

齐射响应方法内的代码

I am developing an android app using php and mysql. This login has a restriction where only active users can logged in. In mysql table column active is set to 1 or 0 for active and inactive, respectively. The problem here is when the value of active is set to 1, it displays not active. Here's my code below

What I have tried:

Android
Code inside volley response method

String userId = jObj.getString("user_id");
String userType = jObj.getString("type");
String userActive = jObj.getString("active");

if (userId != "null") {

    switch (userType)
    {
    case "1":
        Toast.makeText(getApplicationContext(),"Access Denied", Toast.LENGTH_LONG).show();
        break;
    default:
        session.setLogin(true);
        session.setType(userType,userId);
        if(userActive=="1"){
            Intent dashB = new Intent(login_activity.this,MainDashBoard.class);
            startActivity(dashB);
            finish();
        }
        else{
            Toast.makeText(getApplicationContext(),"Not active", Toast.LENGTH_LONG).show();
        }
        break;
    }
} else {
    String errorMsg = jObj.getString("error_msg");
    Toast.makeText(login_activity.this,"Invalid Username or Password", Toast.LENGTH_LONG).show();

推荐答案

你不应该使用 == 字符串运算符,使用 String.equals [ ^ ]。
You should not use the == operator for strings, use String.equals[^].


这篇关于Android使用PHP和mysql登录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆