Click here to Skip to main content
14,828,654 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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:

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();
            Intent dashB = new Intent(login_activity.this,MainDashBoard.class);
            Toast.makeText(getApplicationContext(),"Not active", Toast.LENGTH_LONG).show();
} else {
    String errorMsg = jObj.getString("error_msg");
    Toast.makeText(login_activity.this,"Invalid Username or Password", Toast.LENGTH_LONG).show();
Updated 29-Jul-16 23:42pm
Afzaal Ahmad Zeeshan 30-Jul-16 6:16am
Apart from what Richard has said, would that return "null" or null? There is a difference.

1 solution

You should not use the == operator for strings, use String.equals[^].
Afzaal Ahmad Zeeshan 30-Jul-16 6:16am
Sac Yac 30-Jul-16 12:15pm
Oh...ok thanks. But one big question now is why my volley response is empty whenever user provides an incorrect username and password? Heres the php code

if (isset($user)) {
// user found
$response["error"] = FALSE;
$response["user_id"] = $user["uid"];
$response["type"] = $user["type"];
$response["active"] = $user["active"];
echo json_encode($response);

} else {
// user not found
// echo json with error = 1
$response["error"] = TRUE;
$response["user_id"] = "null";
$response["error_msg"] = "Incorrect email or password!";
echo json_encode($response);

i have even log the output to a text file of what its json object would's the json result below-

{"error":true,"user_id":"null","error_msg":"Incorrect email or password!"}
Richard MacCutchan 30-Jul-16 12:45pm
You will need to debug the PHP code to see why, and check where the values are not getting returned correctly.
Sac Yac 30-Jul-16 16:23pm
Thanks for the help. Actually the response was expecting some values. I did solved the problem.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900