<?php session_start(); if(!$_SESSION['name']) {?> <script type="text/javascript">window.location.href='index.php';</script> <?php } ?> <?php if(isset($_POST["changepsw"])) { $name = $_SESSION['name']; $oldpsw= $_POST["oldpsw"]; $newpsw= $_POST["newpsw"]; $conpsw= $_POST["conpsw"]; require("connection.php"); $qry1 = "SELECT * FROM user where name='$name';"; $re = mysqli_query($con,$qry1); $row = mysqli_fetch_array($re); $dbpsw= $row['password']; if($dbpsw==$oldpsw) { if($newpsw==$conpsw) { $qrys="UPDATE user SET password='$newpsw' WHERE name='$name';"; $results= mysqli_query($con,$qrys); if($results==true) { session_destroy(); ?> <script>alert("Password Change Successfully"); window.location.href = "index.php"; </script> <?php } else { ?> <script>alert("Password Not Changed"); window.location.href = "change-psw.php"; </script> <?php } mysqli_close($con); } else { ?> <script>alert("Password Not Matched"); window.location.href = "change-psw.php"; </script> <?php } } else { ?> <script>alert("Old password is wrong"); window.location.href = "change-psw.php"; </script> <?php } } ?>
Welcome back to shortlearner.com , today we will see how to change password using JavaScript, PHP and MySQL.
first of all we should discuss about overall scenario which we used to reset password.
In first step we make a form (which have three input fields) with the help of HTML, CSS and Bootstrap.
In the second step we match the new password and confirm password with the help of JavaScript.
in case if new password and confirm password are not matched than we will disable the submit button with the help of JQuery.