Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static final String TAG = "SyncToMySQL";
- public static final String JSON_OBJ = "com.android.lifesci_pubmed.SyncToMySQL.JSON_OBJ";
- private String obj_sharedList;
- private static String url_register_code = "http://192.168.1.5:80/myLogin/sync2.php";
- JSONParser jsonParser = new JSONParser();
- // JSON element ids from repsonse of php script:
- private static final String TAG_SUCCESS = "success";
- private static final String TAG_MESSAGE = "message";
- public SyncToMySQL() {
- super(TAG);
- }
- @Override
- protected void onHandleIntent(Intent intent) {
- Log.d("SyncToMySQL", "Intent received");
- obj_sharedList = intent.getStringExtra(SyncToMySQL.JSON_OBJ);
- Log.d("SyncToMySQL", "obj_sharedList: " + obj_sharedList);
- String num = "1";
- // Build paramters
- List<NameValuePair> param = new ArrayList<NameValuePair>();
- param.add(new BasicNameValuePair("_id", num));
- param.add(new BasicNameValuePair("json_sharedlist_object", obj_sharedList));
- JSONObject json = jsonParser.makeHttpRequest(url_register_code, "POST", param);
- // Retrieving json response
- Log.d("Json", json.toString());
- Log.d("SharedList_ListFrragment", "Syncing in progress...");
- }
- <?php
- // include db connect class
- require_once __DIR__.'/db_connect.php';
- // connect to the database
- $db = new DB_CONNECT();
- //Extract json object and place in variable
- $sqlite_json = $_POST['json_sharedlist_object'];
- $sqlite_id = $_POST['_id'];
- $result = mysql_query("INSERT INTO sharedreadinglist(json_sharedlist_object, _id) VALUES ('$sqlite_json', '$sqlite_id')");
- if($result){
- // JSON response
- $response["success"] = 1;
- $response["message"] = "json object inserted successfully!";
- echo json_encode($response);
- }
- else{
- $response["success"] = 0;
- $response["message"] = "json object insertion NOT successful!";
- echo json_encode($response);
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement