Advertisement
Guest User

Untitled

a guest
Jan 19th, 2016
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.90 KB | None | 0 0
  1. <?php
  2. require "init.php";
  3.  
  4. $UserName =$_POST["User_UserName"];
  5. $Password =md5($_POST["User_Password"]);
  6.  
  7. $result = mysqli_query($con,"SELECT User_UserName FROM User WHERE User_UserName = '$UserName' and User_Password='$Password'");
  8. $row = mysqli_fetch_array($result);
  9. $data = $row[0];
  10.  
  11. if($data){
  12. $response["success"] = 1;
  13. $response["message"] = "You have been sucessfully login";
  14. $response["UserName"] = $data;
  15. die(json_encode($response));
  16. }
  17. else
  18. {
  19. $response["success"] = 0;
  20. $response["message"] = "invalid username or password ";
  21. die(json_encode($response));
  22. }
  23.  
  24. mysql_close();
  25. ?>
  26.  
  27. RequestQueue requestQueue;
  28.  
  29. String LoginURL = "..../login.php";
  30. requestQueue = Volley.newRequestQueue(getApplicationContext());
  31.  
  32. btLogin.setOnClickListener(new View.OnClickListener() {
  33. @Override
  34. public void onClick(View v) {
  35.  
  36.  
  37.  
  38.  
  39. StringRequest request = new StringRequest(Request.Method.POST, LoginURL, new Response.Listener<String>() {
  40. @Override
  41. public void onResponse(String response) {
  42. try {
  43. JSONObject jsonObject = new JSONObject(response);
  44. if(jsonObject.names().get(0).equals("success")) {
  45. Toast.makeText(getApplicationContext(),"Success "+jsonObject.getString("UserName"),Toast.LENGTH_SHORT).show();
  46. Intent intent= new Intent(MainActivity.this,Welcome.class);
  47. intent.putExtra("UserName",jsonObject.getString("UserName"));
  48. startActivity(intent);
  49. // startActivity(new Intent(getApplication(),Welcome.class));
  50. }
  51. else
  52. {
  53. Toast.makeText(getApplicationContext(),"Error",Toast.LENGTH_SHORT).show();
  54. }
  55.  
  56. } catch (JSONException e) {
  57. e.printStackTrace();
  58. }
  59.  
  60. }
  61. }, new Response.ErrorListener() {
  62. @Override
  63. public void onErrorResponse(VolleyError error) {
  64.  
  65. }
  66. }){
  67. @Override
  68. protected Map<String, String> getParams() throws AuthFailureError {
  69. Map<String,String> parameters = new HashMap<String, String>();
  70. parameters.put("User_UserName",etEmail.getText().toString());
  71. parameters.put("User_Password",etPassword.getText().toString());
  72.  
  73. return parameters;
  74. }
  75. };
  76.  
  77. requestQueue.add(request);
  78.  
  79.  
  80.  
  81.  
  82. }
  83. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement