Login form using php,Ajax and jquery with mysql, Redirect one to another page using ajax with return result.
Create a index.php and add this code to it
Create a index.php and add this code to it
Create a Login.php<html> <body> <div class="wrap-input100 validate-input" data-validate = "Enter username"> <input class="input100" type="text" id="user" name="username" placeholder="Email"> <span class="focus-input100" data-placeholder=""></span> </div> <div class="wrap-input100 validate-input" data-validate="Enter password"> <input class="input100" type="password" id="pass" name="pass" placeholder="Password"> <span class="focus-input100" data-placeholder=""></span> </div> <div class="container-login100-form-btn"> <input class="input100" type="button" id="logBtn" name="logBtn" placeholder="Login" value="Login"> </div> <script src="https://code.jquery.com/jquery-2.2.4.min.js"></script> <script> $('#logBtn').click(function(event){ user = document.getElementById("user").value; password = document.getElementById("pass").value; $.ajax({ type:"POST", url:"Login.php", async: false, data: {user:user,password:password}, success: function(data){ alert(data); if(data=="admin"){ window.location="https://..Main/<file-name>.php"; } if(data=="user"){ window.location="https://.....<file-name>.php"; } } }); }); </script> </body> </html>
<?php $servername = "localhost"; $username = "root"; $password = "root"; $dbname = "demo"; $conn = new mysqli($servername, $username, $password, $dbname); $user = $_POST['user']; $pass = $_POST['password']; $sql = "SELECT * FROM users WHERE email='$user' AND pass='$pass'"; $result = mysqli_query($conn, $sql); if (mysqli_num_rows($result) > 0) { $sql_1 = "SELECT * FROM users WHERE email='$user' AND pass='$pass' AND type='admin'"; $result_1 = mysqli_query($conn, $sql_1); if (mysqli_num_rows($result_1) > 0){ echo "admin"; exit(0); } else{ echo "user"; exit(0); } } else { $msg = "username/password invalid"; echo $msg; } mysqli_close($conn); ?>
Hey, great blog, but I don’t understand how to add your site in my reader. Can you Help me please?
ReplyDeletebandar slot terpercaya
How To Match Password And Confirm Password Using Jquery In Laravel
ReplyDeleteUsing Jquery, we can match password and confirm password in Laravel. Here you can see, we are using Jquery function and compare both ids of password and confirm password as well as pass message of password is matched or not..
For More Info:- How To Match Password And Confirm Password Using Jquery In Laravel