Advertisement
Guest User

Untitled

a guest
Dec 21st, 2014
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.94 KB | None | 0 0
  1. public static final String TAG = "SyncToMySQL";
  2. public static final String JSON_OBJ = "com.android.lifesci_pubmed.SyncToMySQL.JSON_OBJ";
  3. private String obj_sharedList;
  4. private static String url_register_code = "http://192.168.1.5:80/myLogin/sync2.php";
  5.  
  6. JSONParser jsonParser = new JSONParser();
  7. // JSON element ids from repsonse of php script:
  8. private static final String TAG_SUCCESS = "success";
  9. private static final String TAG_MESSAGE = "message";
  10.  
  11. public SyncToMySQL() {
  12. super(TAG);
  13. }
  14.  
  15. @Override
  16. protected void onHandleIntent(Intent intent) {
  17. Log.d("SyncToMySQL", "Intent received");
  18.  
  19. obj_sharedList = intent.getStringExtra(SyncToMySQL.JSON_OBJ);
  20. Log.d("SyncToMySQL", "obj_sharedList: " + obj_sharedList);
  21.  
  22. String num = "1";
  23.  
  24. // Build paramters
  25. List<NameValuePair> param = new ArrayList<NameValuePair>();
  26. param.add(new BasicNameValuePair("_id", num));
  27. param.add(new BasicNameValuePair("json_sharedlist_object", obj_sharedList));
  28.  
  29. JSONObject json = jsonParser.makeHttpRequest(url_register_code, "POST", param);
  30.  
  31. // Retrieving json response
  32. Log.d("Json", json.toString());
  33.  
  34.  
  35.  
  36. Log.d("SharedList_ListFrragment", "Syncing in progress...");
  37.  
  38. }
  39.  
  40. <?php
  41. // include db connect class
  42. require_once __DIR__.'/db_connect.php';
  43. // connect to the database
  44. $db = new DB_CONNECT();
  45.  
  46.  
  47. //Extract json object and place in variable
  48. $sqlite_json = $_POST['json_sharedlist_object'];
  49. $sqlite_id = $_POST['_id'];
  50.  
  51. $result = mysql_query("INSERT INTO sharedreadinglist(json_sharedlist_object, _id) VALUES ('$sqlite_json', '$sqlite_id')");
  52.  
  53. if($result){
  54. // JSON response
  55. $response["success"] = 1;
  56. $response["message"] = "json object inserted successfully!";
  57.  
  58. echo json_encode($response);
  59. }
  60. else{
  61. $response["success"] = 0;
  62. $response["message"] = "json object insertion NOT successful!";
  63.  
  64. echo json_encode($response);
  65. }
  66.  
  67. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement