title: Login/Register app using volley
body: <p>I am making an android application using android studio for Login/Register and i failed to send the Register information to the .php file.</p>
  
  <p>Here is my code:</p>
  
  <p>For LoginActivity :</p>
  
  <pre><code>import android.app.AlertDialog;
  import android.content.Intent;
  import android.os.Bundle;
  import android.support.v7.app.AppCompatActivity;
  import android.view.View;
  import android.widget.Button;
  import android.widget.EditText;
  
  import com.android.volley.RequestQueue;
  import com.android.volley.Response;
  import com.android.volley.toolbox.Volley;
  
  import org.json.JSONException;
  import org.json.JSONObject;
  
  public class RegisterActivity extends AppCompatActivity {
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_register);
  
      final EditText etAge = (EditText) findViewById(R.id.etAge);
      final EditText etName = (EditText) findViewById(R.id.etName);
      final EditText etUsername = (EditText) findViewById(R.id.etUsername);
      final EditText etPassword = (EditText) findViewById(R.id.etPassword);
      final Button bRegister = (Button) findViewById(R.id.bRegister);
  
      bRegister.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
              final String name = etName.getText().toString();
              final String username = etUsername.getText().toString();
              final int age = Integer.parseInt(etAge.getText().toString());
              final String password = etPassword.getText().toString();
  
              Response.Listener&lt;String&gt; responseListener = new Response.Listener&lt;String&gt;() {
                  @Override
                  public void onResponse(String response) {
                      try {
                          JSONObject jsonResponse = new JSONObject(response);
                          boolean success = jsonResponse.getBoolean("success");
                          if (success) {
                              Intent intent = new Intent(RegisterActivity.this, LoginActivity.class);
                              RegisterActivity.this.startActivity(intent);
                          } else {
                              AlertDialog.Builder builder = new AlertDialog.Builder(RegisterActivity.this);
                              builder.setMessage("Register Failed")
                                      .setNegativeButton("Retry", null)
                                      .create()
                                      .show();
                          }
                      } catch (JSONException e) {
                          e.printStackTrace();
                      }
                  }
              };
  
              RegisterRequest registerRequest = new RegisterRequest(name, username, age, password, responseListener);
              RequestQueue queue = Volley.newRequestQueue(RegisterActivity.this);
              queue.add(registerRequest);
          }
      });
  }
  }
  </code></pre>
  
  <p>For RegisterActivity:</p>
  
  <pre><code>import android.app.AlertDialog;
  import android.content.Intent;
  import android.os.Bundle;
  import android.support.v7.app.AppCompatActivity;
  import android.view.View;
  import android.widget.Button;
  import android.widget.EditText;
  
   import com.android.volley.RequestQueue;
  import com.android.volley.Response;
  import com.android.volley.toolbox.Volley;
  
  import org.json.JSONException;
  import org.json.JSONObject;
  
  public class RegisterActivity extends AppCompatActivity {
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_register);
  
      final EditText etAge = (EditText) findViewById(R.id.etAge);
      final EditText etName = (EditText) findViewById(R.id.etName);
      final EditText etUsername = (EditText) findViewById(R.id.etUsername);
      final EditText etPassword = (EditText) findViewById(R.id.etPassword);
      final Button bRegister = (Button) findViewById(R.id.bRegister);
  
      bRegister.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
              final String name = etName.getText().toString();
              final String username = etUsername.getText().toString();
              final int age = Integer.parseInt(etAge.getText().toString());
              final String password = etPassword.getText().toString();
  
              Response.Listener&lt;String&gt; responseListener = new Response.Listener&lt;String&gt;() {
                  @Override
                  public void onResponse(String response) {
                      try {
                          JSONObject jsonResponse = new JSONObject(response);
                          boolean success = jsonResponse.getBoolean("success");
                          if (success) {
                              Intent intent = new Intent(RegisterActivity.this, LoginActivity.class);
                              RegisterActivity.this.startActivity(intent);
                          } else {
                              AlertDialog.Builder builder = new AlertDialog.Builder(RegisterActivity.this);
                              builder.setMessage("Register Failed")
                                      .setNegativeButton("Retry", null)
                                      .create()
                                      .show();
                          }
                      } catch (JSONException e) {
                          e.printStackTrace();
                      }
                  }
              };
  
              RegisterRequest registerRequest = new RegisterRequest(name, username, age, password, responseListener);
              RequestQueue queue = Volley.newRequestQueue(RegisterActivity.this);
              queue.add(registerRequest);
          }
      });
  }
  }
  </code></pre>
  
  <p>For RegisterRequest:</p>
  
  <pre><code>import com.android.volley.Response;
  import com.android.volley.toolbox.StringRequest;
  
  import java.util.HashMap;
  import java.util.Map;
  
  public class RegisterRequest extends StringRequest {
  private static final String REGISTER_REQUEST_URL = "http://mydomain.hostei.com/Register.php";
  private Map&lt;String, String&gt; params;
  
  public RegisterRequest(String name, String username, int age, String password, Response.Listener&lt;String&gt; listener) {
      super(Method.POST, REGISTER_REQUEST_URL, listener, null);
      params = new HashMap&lt;&gt;();
      params.put("name", name);
      params.put("age", age + "");
      params.put("username", username);
      params.put("password", password);
  }
  
  @Override
  public Map&lt;String, String&gt; getParams() {
      return params;
  }
  }
  </code></pre>
  
  <p>And the Register.php:</p>
  
  <pre><code>$con = mysqli_connect("mysql10.000webhost.com", "a3288368_user", "abcd1234", "a3288368_data");
  
  $name = $_POST["name"];
  $age = $_POST["age"];
  $username = $_POST["username"];
  $password = $_POST["password"];
  $statement = mysqli_prepare($con, "INSERT INTO user (name, age, username, password) VALUES (?, ?, ?, ?)");
  mysqli_stmt_bind_param($statement, "siss", $name, $age, $username, $password);
  mysqli_stmt_execute($statement);
  
  $response = array();
  $response["success"] = true;  
  
  echo json_encode($response);
  </code></pre>
  
  <p>The communication between my database and the Register.php file working properly putting values by hand in the Register.php file.
  But when i am waiting the values form the POST method i failed to communicate between my application and the Register.php</p>
  
  <p>I have added internet permission to my project already,also compiled the volley library.</p>
  
  <p>Any ideas what is going wrong?
  Maybe there is a mistake on my Java code?</p>
  
  <p>Thanks</p>