Guest User

Untitled

a guest
Sep 5th, 2018
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.29 KB | None | 0 0
  1. if( !$conn )
  2.  
  3. {
  4.  
  5. echo "Connection could not be established.";
  6.  
  7. die( print_r( sqlsrv_errors(), true));
  8. }
  9.  
  10. else{
  11. $user_name = $_POST["username"];
  12. $pass_word = $_POST["password"];
  13.  
  14. $sql = "select emp_role,emp_id from employee where emp_loginid =(?) and
  15. emp_password =(?)";
  16. $params = array($user_name,$pass_word);
  17. $options = array( "Scrollable" => SQLSRV_CURSOR_KEYSET );
  18. $stmt = sqlsrv_query( $conn, $sql , $params, $options );
  19.  
  20. $row_count = sqlsrv_num_rows( $stmt );
  21.  
  22. if ($row_count > 0)
  23. while( $row = sqlsrv_fetch_array( $stmt, SQLSRV_FETCH_ASSOC) ){
  24. echo $row["emp_role"];
  25. echo $row["emp_id"];
  26. }
  27. else
  28. echo "username or password is incorrect";
  29. }
  30.  
  31. public class BackgroundWorker extends AsyncTask<String,Void,String> {
  32. Context context;
  33. AlertDialog alertDialog;
  34. String username, password;
  35.  
  36. BackgroundWorker(Context ctx) {
  37.  
  38. context = ctx;
  39. }
  40.  
  41. @Override
  42. protected String doInBackground(String... params) {
  43. String type = params[0];
  44. String login_url = "http://localhost:8080/sqlsrv.php";
  45. if (type.equals("login")) {
  46. try {
  47. username = (String) params[1];
  48. password = (String) params[2];
  49. URL url = new URL( login_url );
  50. HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection();
  51. httpURLConnection.setRequestMethod( "POST" );
  52. httpURLConnection.setDoOutput( true );
  53. httpURLConnection.setDoInput( true );
  54. OutputStream outputStream = httpURLConnection.getOutputStream();
  55. BufferedWriter bufferedWriter = new BufferedWriter( new OutputStreamWriter( outputStream, "UTF-8" ) );
  56. String post_data = URLEncoder.encode( "username", "UTF-8" ) + "=" + URLEncoder.encode( username, "UTF-8" ) + "&"
  57. + URLEncoder.encode( "password", "UTF-8" ) + "=" + URLEncoder.encode( password, "UTF-8" );
  58. bufferedWriter.write( post_data );
  59. bufferedWriter.flush();
  60. bufferedWriter.close();
  61. outputStream.close();
  62. InputStream inputStream = httpURLConnection.getInputStream();
  63. BufferedReader bufferedReader = new BufferedReader( new InputStreamReader( inputStream, "iso-8859-1" ) );
  64. String result = "";
  65. String line = "";
  66. while ((line = bufferedReader.readLine()) != null) {
  67. result += line;
  68. }
  69. bufferedReader.close();
  70. inputStream.close();
  71. httpURLConnection.disconnect();
  72. return result;
  73. } catch (MalformedURLException e) {
  74. e.printStackTrace();
  75. } catch (IOException e) {
  76. e.printStackTrace();
  77. }
  78. }
  79. return null;
  80. }
  81. @Override
  82. protected void onPreExecute() {
  83. alertDialog = new AlertDialog.Builder(context).create();
  84. alertDialog.setTitle("Login Status");
  85. }
  86.  
  87. @Override
  88. protected void onPostExecute(String result) {
  89. /*if(result != null){
  90. Intent intent=new Intent(context,LoginSucess.class);
  91. context.startActivity(intent);
  92. }else{
  93. alertDialog.setMessage(result);
  94. alertDialog.show();
  95. }*/
  96.  
  97. if(result.equals("username or password is incorrect")) {
  98. Toast.makeText( context, result, Toast.LENGTH_LONG ).show();
  99. }
  100. if(result.equals("AD")){
  101. Intent admin=new Intent(context,Admin.class);
  102. context.startActivity(admin);
  103. }
  104. if(result.equals("EN")){
  105. Intent engineer=new Intent(context,Engineer.class);
  106. context.startActivity(engineer);
  107. }
  108. if(result.equals("SC")){
  109. Intent service=new Intent(context,Service.class);
  110. context.startActivity(service);
  111. }
  112. if(result.equals("SLP")){
  113. Intent Sperson=new Intent(context,SalesPerson.class);
  114. context.startActivity(Sperson);
  115. }
  116. if(result.equals("SLSC")){
  117. Intent Sservice=new Intent(context,SalesService.class);
  118. context.startActivity(Sservice);
  119. }
  120. if(result.equals("SLSU")){
  121. Intent SalesSuper=new Intent(context,SalesSupervisior.class);
  122. context.startActivity(SalesSuper);
  123. }
  124. if(result.equals("SU")){
  125. Intent Supervisior=new Intent(context,Supervisior.class);
  126. context.startActivity(Supervisior);
  127. }
  128. }
  129. }
  130.  
  131. if(result.equals("AD")){
  132. Intent admin=new Intent(context,Admin.class);
  133. admin.putExtra("username", username);
  134. context.startActivity(admin);
Add Comment
Please, Sign In to add comment