Advertisement
Guest User

Untitled

a guest
Jan 21st, 2017
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.29 KB | None | 0 0
  1. $(document).ready(function() {
  2.  
  3. $("#login").click(function() {
  4.  
  5. var email = $("#email").val();
  6. var password = $("#password").val();
  7.  
  8. //checking for blank fields
  9. if (email == '' || password == '') {
  10. $('input[type="text"],input[type="password"]').css("border", "2px solid red");
  11. $('input[type="text"],input[type="password"]').css("box-shadow", "0 0 3px red");
  12. alert("Please fill up all the fields");
  13. } else {
  14. $.ajax({
  15. type: "POST",
  16. url: "http://localhost/Reward/applogin.php",
  17. data: {email1: email, password1: password},
  18. dataType: 'JSONP',
  19. crossDomain: true,
  20. cache: false,
  21. success: function(data) {
  22. if (data == 'Invalid Email.......') {
  23. $('input[type="text"]').css({
  24. "border": "2px solid red",
  25. "box-shadow": "0 0 3px red"
  26. });
  27. $('input[type="password"]').css({
  28. "border": "2px solid #00F5FF",
  29. "box-shadow": "0 0 5px #00F5FF"
  30. });
  31. alert(data);
  32. } else if (data == 'Email or Password is incorrect') {
  33. $('input[type="text"],input[type="password"]').css({
  34. "border": "2px solid red",
  35. "box-shadow": "0 0 3px red"
  36. });
  37. alert(data);
  38. } else if (data == 'Successfully Logged in') {
  39. $("form")[0].reset();
  40. $('input[type="text"],input[type="password"]').css({
  41. "border": "2px solid #00F5FF",
  42. "box-shadow": "0 0 5px #00F5FF"
  43. });
  44.  
  45. alert(data);
  46. } else {
  47. alert(data);
  48. }
  49.  
  50. }
  51. })
  52. }
  53. });
  54. });
  55.  
  56. <?php
  57. header('Content-Type: application/json');
  58. // Establishing connection with server..
  59. $con = mysqli_connect("localhost","root","reward");
  60.  
  61. // Selecting Database
  62. $db = mysql_select_db("reward", $con);
  63.  
  64. //Fetching Values from URL
  65. $acc_email=$_POST['email1'];
  66. $acc_pwd= sha1($_POST['password1']); // Password Encryption, If you like you can also leave sha1
  67.  
  68. // check if e-mail address syntax is valid or not
  69. $acc_email = filter_var($acc_email, FILTER_SANITIZE_EMAIL); // sanitizing email(Remove unexpected symbol like <,>,?,#,!, etc.)
  70.  
  71. if (!filter_var($acc_email, FILTER_VALIDATE_EMAIL))
  72. {
  73. echo "Invalid Email";
  74. }
  75. else
  76. {//matching user input email and password with stored email and password in database
  77. $result = mysql_query("SELECT * FROM account WHERE acc_email='$acc_email' AND acc_pwd='$acc_pwd'");
  78. $data = mysql_num_rows($result);
  79.  
  80. if($data==1)
  81. {
  82. echo json_encode("Successfully Logged in");
  83. }
  84. else
  85. {
  86. echo json_encode ("Email or Password is incorrect");
  87. }
  88. }
  89.  
  90. //connection closed
  91. mysql_close ($con);
  92. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement