Advertisement
Guest User

Untitled

a guest
Sep 21st, 2017
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.07 KB | None | 0 0
  1. function.php
  2.  
  3. public function StoreListInfo($list_name,$list_title)
  4. {
  5. $stmt = $this->conn->prepare("INSERT INTO ibeSaveList(list_name,list_title) VALUES(?,?)");
  6. $stmt->bind_param("ss", $list_name, $list_title);
  7. $result = $stmt->execute();
  8. $stmt->close();
  9.  
  10. if($result)
  11. {
  12. $stmt = $this->conn->prepare("SELECT list_name,list_title FROM ibeSaveList WHERE list_title = ?");
  13. $stmt->bind_param("s",$list_title);
  14. $stmt->execute();
  15. $stmt->bind_result($token2,$token3);
  16. while( $stmt->fetch() )
  17. {
  18. $user["list_name"]=$token2;
  19. $user["list_title"]=$token3;
  20. }
  21. $stmt->close();
  22. return $user;
  23. }
  24. else
  25. {
  26. return false;
  27. }
  28. }
  29.  
  30. WebService.php
  31. <?php
  32. require_once 'update_user_info.php';
  33. $db = new update_user_info();
  34. // json response array
  35. $response = array("error" => FALSE);
  36. var_dump($_POST);
  37. if (isset($_POST['list_name']) && isset($_POST['list_title'])) {
  38.  
  39. // receiving the post params
  40. $list_name = $_POST['list_name'];
  41. $list_title = $_POST['list_title'];
  42.  
  43. // create a new user
  44. $user = $db->StoreListInfo($list_name,$list_title);
  45. if ($user) {
  46. // user stored successfully
  47. $response["error"] = FALSE;
  48. $response["user"]["list_name"] = $user["list_name"];
  49. $response["user"]["list_title"] = $user["list_title"];
  50. echo json_encode($response);
  51. } else {
  52. // user failed to store
  53. $response["error"] = TRUE;
  54. $response["error_msg"] = "Unknown error occurred in registration!";
  55. echo json_encode($response);
  56. }
  57.  
  58. } else {
  59. $response["error"] = TRUE;
  60. $response["error_msg"] = "Required parameters (listname,listtitle) is missing!";
  61. echo json_encode($response);
  62. }
  63.  
  64. ?>
  65.  
  66. list.java
  67.  
  68. private void createListUser(final String list_name, final String list_title) {
  69. // Tag used to cancel the request
  70. String cancel_req_tag = "createlist";
  71.  
  72. progressDialog.setMessage("Adding you ...");
  73. showDialog();
  74.  
  75. StringRequest strReq = new StringRequest(Request.Method.POST,
  76. URL_FOR_LIST, new Response.Listener<String>() {
  77.  
  78. @Override
  79. public void onResponse(String response) {
  80. Log.d(TAG, "CreateList Response: " + response.toString());
  81. hideDialog();
  82.  
  83. try {
  84. JSONObject jObj = new JSONObject(response);
  85. boolean error = jObj.getBoolean("error");
  86. // boolean status= jObj.getBoolean("status");
  87.  
  88. if (!error) {
  89. Intent intent = new Intent(getActivity(),
  90. EventDetailActivity.class);
  91. startActivity(intent);
  92.  
  93. } else {
  94.  
  95. String errorMsg = jObj.getString("error_msg");
  96. Toast.makeText(getApplicationContext(),
  97. errorMsg, Toast.LENGTH_LONG).show();
  98. }
  99. } catch (JSONException e) {
  100. e.printStackTrace();
  101. }
  102.  
  103. }
  104. }, new Response.ErrorListener() {
  105.  
  106. @Override
  107. public void onErrorResponse(VolleyError error) {
  108. Log.e(TAG, "List Error: " + error.getMessage());
  109. Toast.makeText(getApplicationContext(),
  110. error.getMessage(), Toast.LENGTH_LONG).show();
  111. hideDialog();
  112. }
  113. }) {
  114. @Override
  115. protected Map<String, String> getParams() {
  116. // Posting params to register url
  117. Map<String, String> params = new HashMap<String, String>();
  118. params.put("list_name", list_name);
  119. params.put("list_title", list_title);
  120. return params;
  121. }
  122. };
  123. // Adding request to request queue
  124. AppSingleton.getInstance(getApplicationContext()).addToRequestQueue(strReq, cancel_req_tag);
  125. }
  126.  
  127. array(2) {
  128. ["list_name"] =>
  129. string(4) "test"
  130. ["list_title"] =>
  131. string(4) "test"
  132. }
  133. {"error":false,"user":{"list_name":"test","list_title":"test"}}
  134.  
  135. array(2) {
  136. ["list_name"] =>
  137. string(4) "test"
  138. ["list_title"] =>
  139. string(4) "test"
  140. }
  141.  
  142. header('Content-Type: application/json');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement