Advertisement
Guest User

Untitled

a guest
Jun 6th, 2016
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.64 KB | None | 0 0
  1. org.json.JSONException: No value for name
  2.  
  3. public class LoginActivity extends AppCompatActivity {
  4.  
  5. @Override
  6. protected void onCreate(Bundle savedInstanceState) {
  7. super.onCreate(savedInstanceState);
  8. setContentView(R.layout.activity_login);
  9.  
  10. final EditText etUsername = (EditText) findViewById(R.id.etUsername);
  11. final EditText etPassword = (EditText) findViewById(R.id.etPassword);
  12. final TextView tvRegisterLink = (TextView) findViewById(R.id.tvRegisterLink);
  13. final Button bLogin = (Button) findViewById(R.id.bSignIn);
  14.  
  15. tvRegisterLink.setOnClickListener(new View.OnClickListener() {
  16. @Override
  17. public void onClick(View v) {
  18. Intent registerIntent = new Intent(LoginActivity.this, RegisterActivity.class);
  19. LoginActivity.this.startActivity(registerIntent);
  20. }
  21. });
  22.  
  23. bLogin.setOnClickListener(new View.OnClickListener() {
  24. @Override
  25. public void onClick(View v) {
  26. final String username = etUsername.getText().toString();
  27. final String password = etPassword.getText().toString();
  28.  
  29. // Response received from the server
  30. Response.Listener<String> responseListener = new Response.Listener<String>() {
  31. @Override
  32. public void onResponse(String response) {
  33. try {
  34. JSONObject jsonResponse = new JSONObject(response);
  35. boolean success = jsonResponse.getBoolean("success");
  36.  
  37. if (success) {
  38. String name = jsonResponse.getString("name");
  39. int age = jsonResponse.getInt("age");
  40.  
  41. Intent intent = new Intent(LoginActivity.this, UserAreaActivity.class);
  42. intent.putExtra("name", name);
  43. intent.putExtra("age", age);
  44. intent.putExtra("username", username);
  45. LoginActivity.this.startActivity(intent);
  46. } else {
  47. AlertDialog.Builder builder = new AlertDialog.Builder(LoginActivity.this);
  48. builder.setMessage("Login Failed")
  49. .setNegativeButton("Retry", null)
  50. .create()
  51. .show();
  52. }
  53.  
  54. } catch (JSONException e) {
  55. e.printStackTrace();
  56. }
  57. }
  58. };
  59.  
  60. LoginRequest loginRequest = new LoginRequest(username, password, responseListener);
  61. RequestQueue queue = Volley.newRequestQueue(LoginActivity.this);
  62. queue.add(loginRequest);
  63. }
  64. });
  65. }
  66. }
  67.  
  68. <?php
  69. $con = "Connection works fine.";
  70.  
  71. $username = $_POST["username"];
  72. $password = $_POST["password"];
  73.  
  74. $statement = mysqli_prepare($con, "SELECT * FROM user WHERE username = ? AND password = ?");
  75. mysqli_stmt_bind_param($statement, "ss", $username, $password);
  76. mysqli_stmt_execute($statement);
  77.  
  78. mysqli_stmt_store_result($statement);
  79. mysqli_stmt_bind_result($statement, $userID, $name, $username, $age,$password);
  80.  
  81. $response = array();
  82. $response["success"] = false;
  83.  
  84. while(mysqli_stmt_fetch($statement)){
  85. $response["success"] = true;
  86. $response["name"] = $name;
  87. $response["age"] = $age;
  88. $response["username"] = $username;
  89. $response["password"] = $password;
  90. }
  91.  
  92. echo json_encode($response);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement