Guest User

Untitled

a guest
Oct 16th, 2017
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.00 KB | None | 0 0
  1. dependencies{
  2. compile 'com.squareup.okhttp:okhttp:2.0.0'
  3. }
  4.  
  5. btnRegistration.setOnClickListener(new View.OnClickListener() {
  6. @Override
  7. public void onClick(View view) {
  8.  
  9. try {
  10.  
  11. String UserName = etUserName.getText().toString();
  12. String Password = etPassword.getText().toString();
  13. String DOB = etDob.getText().toString();
  14. String Phone = etPhone.getText().toString();
  15.  
  16.  
  17. String inserturl = "http://10.0.2.2/Project/Registration.php?insert&username="+UserName+"&password="+Password
  18. +"&dob="+DOB+"phone="+Phone;
  19.  
  20. JSONObject jsonObject = new JSONParser().SelectData(inserturl);
  21.  
  22. if (jsonObject != null)
  23. {
  24. Toast.makeText(MainActivity.this, jsonObject.toString(), Toast.LENGTH_SHORT).show();
  25.  
  26. }
  27.  
  28.  
  29. }catch (Exception ex){
  30.  
  31. Log.i("Error",ex.toString());
  32. }
  33.  
  34.  
  35. }
  36.  
  37. });
  38.  
  39. public class JSONParser {
  40.  
  41.  
  42. public JSONObject SelectData(String url){
  43.  
  44. try {
  45.  
  46. OkHttpClient client = new OkHttpClient();
  47. Request request = new Request.Builder().url(url).build();
  48. Response response = client.newCall(request).execute();
  49. String data = response.body().string();
  50. JSONObject jsonObject = new JSONObject(data);
  51. return jsonObject;
  52.  
  53.  
  54. }catch(Exception ex){
  55.  
  56.  
  57. return null;
  58.  
  59. }
  60. }
  61. }
  62.  
  63. <?php
  64.  
  65. include "Mysql.php";
  66. $username = $_GET['user'];
  67. $password = $_GET['pass'];
  68. $dob =date("Y-m-d" ,strtotime($_GET['dob']));
  69. $phone = $_GET['phone'];
  70.  
  71. $sql_query = "insert into registration(username,password,dob,phoneno) values('$username','$password','$dob','$phone')";
  72.  
  73. if(mysqli_query($conn,$sql_query))
  74. {
  75. echo"<h3>Data Insertion Success...</h3>";
  76. }else{
  77. echo "Data Insertion error..".mysqli_error($conn);
  78. }
  79.  
  80. ?>
Add Comment
Please, Sign In to add comment