Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Response.Listener<String> responseListener = new Response.Listener<String>() {
- @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(username, email, password, responseListener);
- RequestQueue queue = Volley.newRequestQueue(RegisterActivity.this);
- queue.add(registerRequest);
- }
- });
- }
- $username = $_POST["username"];
- $email = $_POST["email"];
- $password = $_POST["password"];
- $statement = mysqli_prepare($con, "INSERT INTO data (username, email, password) VALUES (?, ?, ?, ?)");
- mysqli_stmt_bind_param($statement, "sss", $username, $email, $password);
- mysqli_stmt_execute($statement);
- $response = array();
- $response["success"] = true;
- echo json_encode($response);
- public RegisterRequest(String username, String email, String password, Response.Listener<String> listener){
- /*
- NExt line means we are going to pass some information into the register.php
- */
- super(Method.POST, REGISTER_REQUEST_URL, listener, null);
- /*
- This is how we pass in the information from the register to the thing, we are using a hashmap
- */
- params = new HashMap<>();
- params.put("username", username);
- params.put("email", email);
- params.put("password", password);
- }
- /*
- Volley needs to get the data so we do a get params
- Which gives us this method
- */
- @Override
- public Map<String, String> getParams() {
- return params;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement