Guest User

Untitled

a guest
Oct 29th, 2017
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.14 KB | None | 0 0
  1. <?php header('Content-Type: application/json; charset=utf-8');
  2.  
  3. /*
  4. * Following code will update a product information
  5. * A product is identified by product id (pid)
  6. */
  7.  
  8. // array for JSON response
  9. $response = array();
  10.  
  11. // check for required fields
  12. if (isset($_POST['quotes_id']) && isset($_POST['quote']) && isset($_POST['uid']) && isset($_POST['imageName']) && isset($_POST['nameOfCreator']) ) {
  13.  
  14. $quotes_id = $_POST['quotes_id'];
  15. $quote = $_POST['quote'];
  16. $uid = $_POST['uid'];
  17. $imageName = $_POST['imageName'];
  18. $nameOfCreator = $_POST['nameOfCreator'];
  19.  
  20. // include db connect class
  21. require_once __DIR__ . '/db_connect.php';
  22.  
  23. // connecting to db
  24. $db = new DB_CONNECT();
  25.  
  26. // mysql update row with matched pid
  27. $result = mysql_query("INSERT INTO quotes SET quote = '$quote', uid = '$uid', imageName = '$imageName', nameOfCreator = '$nameOfCreator'");
  28.  
  29. // check if row inserted or not
  30. if ($result) {
  31. // successfully updated
  32. $response["success"] = 1;
  33. $response["message"] = "Product successfully updated.";
  34.  
  35. // echoing JSON response
  36. echo json_encode($response);
  37. } else {
  38.  
  39. }
  40. } else {
  41. // required field is missing
  42. $response["success"] = 0;
  43. $response["message"] = "Required field(s) is missing";
  44.  
  45. // echoing JSON response
  46. echo json_encode($response);
  47. }
  48. ?>
  49.  
  50. private void setData() {
  51. Map<String, String> jsonParams = new HashMap<String, String>();
  52. jsonParams.put(StaticVariables.QUOTES_ID, null);
  53. jsonParams.put(StaticVariables.QUOTE, "ööö");
  54. jsonParams.put(StaticVariables.UID, "112");
  55. jsonParams.put(StaticVariables.IMAGE_NAME, "112v1.jpg");
  56. jsonParams.put("nameOfCreator", "aa");
  57.  
  58. JsonObjectRequest myRequest = new JsonObjectRequest(
  59. Request.Method.POST,
  60. StaticVariables.url_insert_quote,
  61. new JSONObject(jsonParams),
  62.  
  63. new Response.Listener<JSONObject>() {
  64. @Override
  65. public void onResponse(JSONObject response) {
  66. // verificationSuccess(response);
  67. Log.e("JA", "nice");
  68. }
  69. },
  70. new Response.ErrorListener() {
  71. @Override
  72. public void onErrorResponse(VolleyError error) {
  73. // verificationFailed(error);
  74. }
  75. }) {
  76.  
  77. @Override
  78. public Map<String, String> getHeaders() throws AuthFailureError {
  79. HashMap<String, String> headers = new HashMap<String, String>();
  80. headers.put("Content-Type", "application/json; charset=utf-8");
  81. headers.put("User-agent", "My useragent");
  82. return headers;
  83. }
  84. };
  85. AppController.getInstance().addToRequestQueue(myRequest, "tag");
  86. }
  87.  
  88. private void registerUser(){
  89. final String username = editTextUsername.getText().toString().trim();
  90. final String password = editTextPassword.getText().toString().trim();
  91.  
  92.  
  93. StringRequest stringRequest = new StringRequest(Request.Method.POST, REGISTER_URL,
  94. new Response.Listener<String>() {
  95. @Override
  96. public void onResponse(String response) {
  97. //do stuffs with response of post
  98. }
  99. },
  100. new Response.ErrorListener() {
  101. @Override
  102. public void onErrorResponse(VolleyError error) {
  103. //do stuffs with response erroe
  104. }
  105. }){
  106. @Override
  107. protected Map<String,String> getParams(){
  108. Map<String,String> params = new HashMap<String, String>();
  109.  
  110. params.put(KEY_PASSWORD,password);
  111. params.put(KEY_EMAIL, email);
  112. return params;
  113. }
  114.  
  115. };
  116.  
  117. RequestQueue requestQueue = Volley.newRequestQueue(this);
  118. requestQueue.add(stringRequest);
  119. }
  120.  
  121. <uses-permission android:name="android.permission.INTERNET" />
  122.  
  123. compile 'com.mcxiaoke.volley:library:1.0.19'
Add Comment
Please, Sign In to add comment