Advertisement
Guest User

Untitled

a guest
Jun 17th, 2016
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.36 KB | None | 0 0
  1. Response.Listener<String> responseListener = new Response.Listener<String>() {
  2. @Override
  3. public void onResponse(String response) {
  4. try {
  5. JSONObject jsonResponse = new JSONObject(response);
  6. boolean success = jsonResponse.getBoolean("success");
  7. if (success) {
  8. Intent intent = new Intent(RegisterActivity.this, LoginActivity.class);
  9. RegisterActivity.this.startActivity(intent);
  10. } else {
  11. AlertDialog.Builder builder = new AlertDialog.Builder(RegisterActivity.this);
  12. builder.setMessage("Register Failed")
  13. .setNegativeButton("Retry", null)
  14. .create()
  15. .show();
  16. }
  17. } catch (JSONException e) {
  18. e.printStackTrace();
  19. }
  20. }
  21. };
  22.  
  23. RegisterRequest registerRequest = new RegisterRequest(username, email, password, responseListener);
  24. RequestQueue queue = Volley.newRequestQueue(RegisterActivity.this);
  25. queue.add(registerRequest);
  26. }
  27. });
  28. }
  29.  
  30. $username = $_POST["username"];
  31. $email = $_POST["email"];
  32. $password = $_POST["password"];
  33.  
  34. $statement = mysqli_prepare($con, "INSERT INTO data (username, email, password) VALUES (?, ?, ?, ?)");
  35. mysqli_stmt_bind_param($statement, "sss", $username, $email, $password);
  36. mysqli_stmt_execute($statement);
  37.  
  38. $response = array();
  39. $response["success"] = true;
  40.  
  41. echo json_encode($response);
  42.  
  43. public RegisterRequest(String username, String email, String password, Response.Listener<String> listener){
  44. /*
  45. NExt line means we are going to pass some information into the register.php
  46. */
  47. super(Method.POST, REGISTER_REQUEST_URL, listener, null);
  48. /*
  49. This is how we pass in the information from the register to the thing, we are using a hashmap
  50. */
  51. params = new HashMap<>();
  52. params.put("username", username);
  53. params.put("email", email);
  54. params.put("password", password);
  55.  
  56. }
  57. /*
  58. Volley needs to get the data so we do a get params
  59. Which gives us this method
  60. */
  61.  
  62. @Override
  63. public Map<String, String> getParams() {
  64. return params;
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement