Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $(document).ready(function() {
- $("#login").click(function() {
- var email = $("#email").val();
- var password = $("#password").val();
- //checking for blank fields
- if (email == '' || password == '') {
- $('input[type="text"],input[type="password"]').css("border", "2px solid red");
- $('input[type="text"],input[type="password"]').css("box-shadow", "0 0 3px red");
- alert("Please fill up all the fields");
- } else {
- $.ajax({
- type: "POST",
- url: "http://localhost/Reward/applogin.php",
- data: {email1: email, password1: password},
- dataType: 'JSONP',
- crossDomain: true,
- cache: false,
- success: function(data) {
- if (data == 'Invalid Email.......') {
- $('input[type="text"]').css({
- "border": "2px solid red",
- "box-shadow": "0 0 3px red"
- });
- $('input[type="password"]').css({
- "border": "2px solid #00F5FF",
- "box-shadow": "0 0 5px #00F5FF"
- });
- alert(data);
- } else if (data == 'Email or Password is incorrect') {
- $('input[type="text"],input[type="password"]').css({
- "border": "2px solid red",
- "box-shadow": "0 0 3px red"
- });
- alert(data);
- } else if (data == 'Successfully Logged in') {
- $("form")[0].reset();
- $('input[type="text"],input[type="password"]').css({
- "border": "2px solid #00F5FF",
- "box-shadow": "0 0 5px #00F5FF"
- });
- alert(data);
- } else {
- alert(data);
- }
- }
- })
- }
- });
- });
- <?php
- header('Content-Type: application/json');
- // Establishing connection with server..
- $con = mysqli_connect("localhost","root","reward");
- // Selecting Database
- $db = mysql_select_db("reward", $con);
- //Fetching Values from URL
- $acc_email=$_POST['email1'];
- $acc_pwd= sha1($_POST['password1']); // Password Encryption, If you like you can also leave sha1
- // check if e-mail address syntax is valid or not
- $acc_email = filter_var($acc_email, FILTER_SANITIZE_EMAIL); // sanitizing email(Remove unexpected symbol like <,>,?,#,!, etc.)
- if (!filter_var($acc_email, FILTER_VALIDATE_EMAIL))
- {
- echo "Invalid Email";
- }
- else
- {//matching user input email and password with stored email and password in database
- $result = mysql_query("SELECT * FROM account WHERE acc_email='$acc_email' AND acc_pwd='$acc_pwd'");
- $data = mysql_num_rows($result);
- if($data==1)
- {
- echo json_encode("Successfully Logged in");
- }
- else
- {
- echo json_encode ("Email or Password is incorrect");
- }
- }
- //connection closed
- mysql_close ($con);
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement