Advertisement
Guest User

Untitled

a guest
May 2nd, 2016
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.45 KB | None | 0 0
  1. try {
  2. URL url = new URL("mydburl/create.php");
  3. conn = (HttpURLConnection) url.openConnection();
  4. conn.setRequestMethod("POST");
  5. conn.setDoOutput(true);
  6. //conn.setDoInput(true);
  7. conn.setRequestProperty("Content-Type", "application/json; charset=UTF-8");
  8. //conn.setRequestProperty("Accept", "application/json");
  9. //conn.connect();
  10.  
  11. //Log.d("In Async param",params[0]);
  12.  
  13. String title = params[0];
  14. // Log.d("In Async title",title);
  15.  
  16. jsonObj = new JSONObject();
  17. jsonObj.put("title", title);
  18. //Log.d("In Async Json toString",jsonObj.toString());
  19. } catch (MalformedURLException e) {
  20. e.printStackTrace();
  21. } catch (ProtocolException e) {
  22. e.printStackTrace();
  23. } catch (IOException e) {
  24. e.printStackTrace();
  25. } catch (JSONException e) {
  26. e.printStackTrace();
  27. }
  28. try {
  29.  
  30. os = (conn.getOutputStream());
  31. os.write(jsonObj.toString().getBytes("UTF-8"));
  32. //os.flush();
  33. os.close();
  34. } catch (IOException e) {
  35. e.printStackTrace();
  36. }
  37.  
  38. try {
  39. Log.e("connection status",conn.getResponseMessage());
  40. InputStream in = new BufferedInputStream(conn.getInputStream());
  41. BufferedReader reader = new BufferedReader(new InputStreamReader(in));
  42. strBuilder = new StringBuilder();
  43. String line;
  44. while ((line = reader.readLine()) != null) {
  45. strBuilder.append(line);
  46. }
  47. os.close();
  48. reader.close();
  49. conn.disconnect();
  50.  
  51. } catch (IOException e) {
  52. e.printStackTrace();
  53. }
  54.  
  55. Log.d("In Async param",params[0]);
  56. Log.d("In Async Json toString",jsonObj.toString());
  57.  
  58. <?php
  59. $response = array();
  60. $servername = "myservername";
  61. $username = "user";
  62. $password = "pwd";
  63. $dbname = "myDB";
  64.  
  65. $con=mysql_connect("$servername","$username","$password");
  66. mysql_select_db("$dbname", $con);
  67. $title=$_POST['title'];
  68. mysql_query("INSERT INTO Test(title) VALUES ('$title')");
  69. header('Content-type: application/json; charset=UTF-8');
  70. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement