Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JSONObject isn't encoding like it should be? #45

Closed
yashkumaratri opened this issue Jun 10, 2017 · 1 comment
Closed

JSONObject isn't encoding like it should be? #45

yashkumaratri opened this issue Jun 10, 2017 · 1 comment

Comments

@yashkumaratri
Copy link

This is server side code

<?php
require('connection.php');
require('functions.php');

$inputJSON = file_get_contents('php://input');
$aReuestData = json_decode( $inputJSON, TRUE ); //convert JSON into array

 $user_email = $aReuestData['user_email'];
 $user_password = $aReuestData['user_password'];
  $user_uniq = $aReuestData['user_uniq_id'];

if((($user_password !='') && ($user_email !=''))|| ($user_uniq!=''))
{
    $uname = $user_email;
    $pword = $user_password;
    $format ='json';    
    if(($user_password !='') && ($user_email !='')){
    echo $checkUser = checkLogin($uname,$pword);
    }
    else{
        $checkUser = checkLoginFacebook($user_uniq);
    }
    //print_r($checkUser);
    if($checkUser['id'] > 0)
    {
        $result = $checkUser; 
    }else{
        $result = "false";
    }
}else{

    $result = "Enter username and password";

}

$records = array("result"=> $result); 

echo $_REQUEST['jsoncallback'].  json_encode($records);

?>

and my code for login activity is

 final JSONObject jsonObject = new JSONObject();

        try {

            jsonObject.put("user_email",username.getText().toString().trim());
            jsonObject.put("user_password",password.getText().toString().trim());
        } catch (JSONException e) {
            e.printStackTrace();
        }

        requestQueue.start();
        final String url = "http://demo4u.org/leaveapp/ws/login.php";
        send.setText(jsonObject.toString());
        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.POST, url, jsonObject,
                        new Response.Listener<JSONObject>() {
                            @Override
                            public void onResponse(JSONObject response) {
                                Toast.makeText(Login.this,"Passed",Toast.LENGTH_LONG).show();
                                hello.setText(response.toString());

                            }
                        }, new Response.ErrorListener() {
                    @Override
                    public void onErrorResponse(VolleyError error) {
                        Toast.makeText(Login.this,"Error",Toast.LENGTH_LONG).show();
                    }
                }

                );
                requestQueue.add(jsonObjectRequest);
            }
        });

and the only thing that I get returned is

$result = "Enter username and password";

what am I doing wrong? am I to include JSON header or something ???

Please reply in detailed view cause I'm new to android.....
SHOWCASE your skills please....

@jpd236
Copy link
Collaborator

jpd236 commented Jun 11, 2017

If you have questions about code or how to use Volley, I would suggest another venue (like the volley-users Google Group or StackOverflow, perhaps). This is an issue tracker to report bugs with Volley.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants