title: JSON response from PHP script
body: <p>I am building a registration system for Android. I can add data to the database,which is good. Now I want to add some JSON that will notify the user successful registration or different errors. ie</p>
  
  <pre><code>{
    "status":"success",
    "message":"Successful Registration"
  
  }
  </code></pre>
  
  <p>or</p>
  
  <pre><code> {
    "status":"fail",
    "message":"Please enter your name"
  
  }
  </code></pre>
  
  <p>etc.</p>
  
  <p>Here is my php script.</p>
  
  <pre><code>&lt;?php
     require "init.php";
     $j = new stdClass();
     $name = $_POST['name'];
     $user_name = $_POST['user_name'];
      $user_pass = md5(md5($_POST['user_name']).$_POST['user_pass']);
      if(!$name){
      json_encode(array('status' =&gt; 'fail', 'message' =&gt; 'Please enter your    
      name'));
     }
     $sql_query = "insert into user_info    
    values('$name','$user_name','$user_pass');";
  
     if(mysqli_query($con,$sql_query)){
  
      json_encode(array('status' =&gt; 'success', 'message' =&gt; 'Successfully 
      registered'));
  
    }else{
  
     json_encode(array('status' =&gt; 'fail', 'message' =&gt; 'Could not   
     register'));
    }
  
  
  
   ?&gt;
  </code></pre>
  
  <p>With this script I can not detect any JSON repsonse from my Java code,even if I add data successfully.</p>
  
  <pre><code>  private void registerUser(final String name, final String userName,
                            final String password) {
      // Tag used to cancel the request
      String tag_string_req = "req_register";
  
  
      StringRequest strReq = new StringRequest(Request.Method.POST,
              "MY_LINK_GOES_HERE", new Response.Listener&lt;String&gt;() {
  
          @Override
          public void onResponse(String response) {
              Log.d("Response", "Register Response: " + response.toString());
  
              Toast.makeText(getApplicationContext(), "User successfully registered. Try login now!", Toast.LENGTH_LONG).show();
  
              // Launch login activity
              Intent intent = new Intent(
                      Register.this,
                      MainActivity.class);
              startActivity(intent);
              finish();
          }
      }, new Response.ErrorListener() {
  
          @Override
          public void onErrorResponse(VolleyError error) {
              Log.e("Error", "Registration Error: " + error.getMessage());
              Toast.makeText(getApplicationContext(),
                      error.getMessage(), Toast.LENGTH_LONG).show();
  
          }
      }) {
  
          @Override
          protected Map&lt;String, String&gt; getParams() {
              // Posting params to register url
              Map&lt;String, String&gt; params = new HashMap&lt;String, String&gt;();
              params.put("name", name);
              params.put("user_name", userName);
              params.put("user_pass", password);
  
              return params;
          }
  
      };
  
      // Adding request to request queue
      AppController.getInstance().addToRequestQueue(strReq, tag_string_req);
  }
  </code></pre>
  
  <p>The line</p>
  
  <pre><code>Log.d("Response", "Register Response: " + response.toString());
  </code></pre>
  
  <p>gives me nothing.</p>
  
  <p>Any ideas?</p>
  
  <p>Thank you.</p>