Advertisement
Guest User

Untitled

a guest
Jul 18th, 2016
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.43 KB | None | 0 0
  1. <?php
  2. $con = mysqli_connect("my_host", "my_user", "my_password", "my_database");
  3.  
  4. $username = $_POST["username"];
  5. $password = $_POST["password"];
  6.  
  7. $statement = mysqli_prepare($con, "SELECT * FROM user WHERE username = ? AND password = ?");
  8. mysqli_stmt_bind_param($statement, "ss", $username, $password);
  9. mysqli_stmt_execute($statement);
  10.  
  11. mysqli_stmt_store_result($statement);
  12. mysqli_stmt_bind_result($statement, $userID, $name, $username, $password);
  13.  
  14. $response = array();
  15. $response["success"] = false;
  16.  
  17. while(mysqli_stmt_fetch($statement)){
  18. $response["success"] = true;
  19. $response["name"] = $name;
  20. $response["username"] = $username;
  21. $response["password"] = $password;
  22. }
  23.  
  24. echo json_encode($response);
  25. ?>
  26.  
  27. public void onResponse(String response) {
  28. try {
  29. JSONObject jsonResponse = new JSONObject(response);
  30. boolean success = jsonResponse.getBoolean("success");
  31.  
  32. if (success) {
  33. String name = jsonResponse.getString("name");
  34.  
  35. Intent intent = new Intent(LoginActivity.this, WelcomeActivity.class);
  36. intent.putExtra("name", name);
  37. intent.putExtra("username", username);
  38. LoginActivity.this.startActivity(intent);
  39. } else {
  40. AlertDialog.Builder builder = new AlertDialog.Builder(LoginActivity.this);
  41. builder.setMessage("Login Failed")
  42. .setNegativeButton("Retry", null)
  43. .create()
  44. .show();
  45. }
  46.  
  47. } catch (JSONException e) {
  48. e.printStackTrace();
  49. }
  50. }
  51. };
  52.  
  53. LoginRequest loginRequest = new LoginRequest(username, password, responseListener);
  54. RequestQueue queue = Volley.newRequestQueue(LoginActivity.this);
  55. queue.add(loginRequest);
  56. }
  57.  
  58. 07-18 15:58:34.729 29396-29402/com.example.arthurf.tcc.app W/art: Suspending all threads took: 10.852ms
  59. 07-18 15:58:34.887 29396-29396/com.example.arthurf.tcc.app W/System.err: org.json.JSONException: Value <br><table of type java.lang.String cannot be converted to JSONObject
  60. 07-18 15:58:34.887 29396-29396/com.example.arthurf.tcc.app W/System.err: at org.json.JSON.typeMismatch(JSON.java:111)
  61. 07-18 15:58:34.887 29396-29396/com.example.arthurf.tcc.app W/System.err: at org.json.JSONObject.<init>(JSONObject.java:160)
  62. 07-18 15:58:34.887 29396-29396/com.example.arthurf.tcc.app W/System.err: at org.json.JSONObject.<init>(JSONObject.java:173)
  63. 07-18 15:58:34.887 29396-29396/com.example.arthurf.tcc.app W/System.err: at com.example.arthurf.tcc.app.LoginActivity$1$1.onResponse(LoginActivity.java:40)
  64. 07-18 15:58:34.887 29396-29396/com.example.arthurf.tcc.app W/System.err: at com.example.arthurf.tcc.app.LoginActivity$1$1.onResponse(LoginActivity.java:36)
  65. 07-18 15:58:34.887 29396-29396/com.example.arthurf.tcc.app W/System.err: at com.android.volley.toolbox.StringRequest.deliverResponse(StringRequest.java:60)
  66. 07-18 15:58:34.887 29396-29396/com.example.arthurf.tcc.app W/System.err: at com.android.volley.toolbox.StringRequest.deliverResponse(StringRequest.java:30)
  67. 07-18 15:58:34.887 29396-29396/com.example.arthurf.tcc.app W/System.err: at com.android.volley.ExecutorDelivery$ResponseDeliveryRunnable.run(ExecutorDelivery.java:99)
  68. 07-18 15:58:34.887 29396-29396/com.example.arthurf.tcc.app W/System.err: at android.os.Handler.handleCallback(Handler.java:739)
  69. 07-18 15:58:34.887 29396-29396/com.example.arthurf.tcc.app W/System.err: at android.os.Handler.dispatchMessage(Handler.java:95)
  70. 07-18 15:58:34.887 29396-29396/com.example.arthurf.tcc.app W/System.err: at android.os.Looper.loop(Looper.java:148)
  71. 07-18 15:58:34.887 29396-29396/com.example.arthurf.tcc.app W/System.err: at android.app.ActivityThread.main(ActivityThread.java:5417)
  72. 07-18 15:58:34.887 29396-29396/com.example.arthurf.tcc.app W/System.err: at java.lang.reflect.Method.invoke(Native Method)
  73. 07-18 15:58:34.887 29396-29396/com.example.arthurf.tcc.app W/System.err: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
  74. 07-18 15:58:34.887 29396-29396/com.example.arthurf.tcc.app W/System.err: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement