Guest User

Untitled

a guest
Jun 26th, 2018
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.12 KB | None | 0 0
  1. private void registerUser() {
  2. JSONObject postObject = new JSONObject();
  3. RequestQueue queue = Volley.newRequestQueue(this);
  4. JSONObject historyObject = new JSONObject();
  5.  
  6. String url ="http://helpinghandbd.org/app/index.php";
  7. try {
  8. //historyObject.put("id","1");
  9. historyObject.put("email","1234");
  10. historyObject.put("password","1234");
  11. postObject.put("user",historyObject);
  12. } catch (JSONException e) {
  13. e.printStackTrace();
  14. }
  15.  
  16. Log.e("LoginActivityJsonObject",""+postObject);
  17. JsonObjectRequest objRequest = new JsonObjectRequest(Request.Method.POST, url,postObject,
  18. new Response.Listener<JSONObject>() {
  19. @Override
  20. public void onResponse(JSONObject response) {
  21. Log.e("LoginActivity","OnResponse: "+response);
  22. Toast.makeText(LoginActivity.this, String.valueOf(response), Toast.LENGTH_LONG).show();
  23. }
  24. }, new Response.ErrorListener() {
  25. @Override
  26. public void onErrorResponse(VolleyError error) {
  27. Log.e("OnError", String.valueOf(error.getMessage()));
  28. }
  29. });
  30.  
  31. queue.add(objRequest);
  32.  
  33. }
  34.  
  35. { 'user':{
  36. 'email':'1234',
  37. 'password':'1234'
  38. }
  39. }
  40.  
  41. <?php
  42.  
  43. $data = file_get_contents("php://input");
  44. //echo $data; -> //{ 'user':{'email':'1234','password':'1234'}};
  45. $decode = json_decode($data,true);
  46. $email = $decode->user['email'];
  47. $password = $decode->user['passowrd'];
  48.  
  49. $servername = "localhost";
  50. $username = "helpinghandbd_app";
  51. $password = "Demopass000";
  52. $dbname = "helpinghandbd_app";
  53.  
  54. // Create connection
  55. $conn = new mysqli($servername, $username, $password, $dbname);
  56. // Check connection
  57. if ($conn->connect_error) {
  58. die("Connection failed: " . $conn->connect_error);
  59. }
  60.  
  61. //$data = file_get_contents("php://input");
  62. //{ 'user':{'email':'1234','password':'1234'}};
  63.  
  64.  
  65.  
  66. $sql = "INSERT INTO users (id,email,password)
  67. VALUES (null, '$email', '$password')";
  68.  
  69. if ($conn->query($sql) === TRUE) {
  70. echo "New record created successfully";
  71. } else {
  72. echo "Error: " . $sql . "<br>" . $conn->error;
  73. }
  74.  
  75.  
  76.  
  77. $conn->close();
Add Comment
Please, Sign In to add comment