Advertisement
Guest User

Untitled

a guest
Jan 29th, 2017
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.89 KB | None | 0 0
  1. BasicNetwork.performRequest: Unexpected response code 400
  2.  
  3. <?php
  4.  
  5. if ($_SERVER['REQUEST_METHOD']=='POST'){
  6. $user = $_POST['email'];
  7. $pass = $_POST['password'];
  8.  
  9. $sql = "select * from users where email = '$user' AND password = '$pass'";
  10.  
  11. require_once('config.php');
  12. $result = mysqli_query($con , $sql);
  13. $check = mysqli_fetch_array($result);
  14.  
  15. if(isset($check)){
  16. echo "success";
  17. }else{
  18. echo "failure";
  19. }
  20. mysqli_close($con);
  21. }
  22. ?>
  23.  
  24. <?php
  25. $serverName = "localhost";
  26. $userName = "root";
  27. $password = "";
  28. $dbName = "testDb"
  29.  
  30. $con = mysqli_connect($serverName , $userName , $password , $dbName) or die("connect failed");
  31. ?>
  32.  
  33. @Override
  34. protected void onCreate(@Nullable Bundle savedInstanceState) {
  35. super.onCreate(savedInstanceState);
  36. setContentView(R.layout.activity_login);
  37.  
  38. editTextEmail = (EditText) findViewById(R.id.editTextEmail);
  39. editTextPassword = (EditText) findViewById(R.id.editTextPassword);
  40. buttonLogin = (Button) findViewById(R.id.buttonLogin);
  41. buttonLogin.setOnClickListener(new View.OnClickListener() {
  42. @Override
  43. public void onClick(View v) {
  44. login();
  45. }
  46. });
  47. }
  48.  
  49.  
  50. @Override
  51. protected void onResume() {
  52. super.onResume();
  53.  
  54. SharedPreferences sharedPreferences = getSharedPreferences(config.SHARED_PREF_NAME , Context.MODE_PRIVATE);
  55. loggedIn = sharedPreferences.getBoolean(config.LOGGEDIN_SHARED_PREF , false);
  56. Log.e("txt" , "text is : " + loggedIn);
  57. if (loggedIn){
  58. Intent intent = new Intent(loginActivity.this , profileActivity.class);
  59. startActivity(intent);
  60. }
  61. }
  62.  
  63. private void login(){
  64.  
  65. final String email = editTextEmail.getText().toString().trim();
  66. final String password = editTextPassword.getText().toString().trim();
  67.  
  68. StringRequest stringRequest = new StringRequest(Request.Method.POST, config.LOGIN_URL, new Response.Listener<String>() {
  69. @Override
  70. public void onResponse(String response) {
  71. Log.i("StartActivity", response.toString());
  72. if(response.equalsIgnoreCase(config.LOGIN_SUCCESS)){
  73. //Creating a shared preference
  74. SharedPreferences sharedPreferences = loginActivity.this.getSharedPreferences(config.SHARED_PREF_NAME, Context.MODE_PRIVATE);
  75.  
  76. //Creating editor to store values to shared preferences
  77. SharedPreferences.Editor editor = sharedPreferences.edit();
  78.  
  79. //Adding values to editor
  80. editor.putBoolean(config.LOGGEDIN_SHARED_PREF, true);
  81. editor.putString(config.EMAIL_SHARED_PREF, email);
  82. //Saving values to editor
  83. editor.commit();
  84.  
  85. //Starting profile activity
  86. Intent intent = new Intent(loginActivity.this, profileActivity.class);
  87. startActivity(intent);
  88. }else{
  89. //If the server response is not success
  90. //Displaying an error message on toast
  91. Toast.makeText(loginActivity.this, "Invalid username or password", Toast.LENGTH_LONG).show();
  92. Log.e("s" , "invalid sssssssssssssssssssssss");
  93. }
  94. }
  95. }, new Response.ErrorListener() {
  96. @Override
  97. public void onErrorResponse(VolleyError error) {
  98.  
  99. }
  100. }){
  101. @Override
  102. public Map<String, String> getParams() {
  103. Map<String,String> params = new HashMap<>();
  104. params.put(config.KEY_EMAIL, email);
  105. params.put(config.KEY_PASSWORD, password);
  106. return params;
  107. }
  108. };
  109.  
  110. RequestQueue requestQueue = Volley.newRequestQueue(this);
  111. requestQueue.add(stringRequest);
  112. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement