Ask Question

Menu

How to change login password in PHP


<?php
session_start();
$name = $_SESSION["name"];
$con = mysqli_connect('127.0.0.1:3306','root','','admin') or die('Unable To connect');
if(count($_POST)>0) {
$result = mysqli_query($con,"SELECT *from student WHERE name='" . $name . "'");
$row=mysqli_fetch_array($result);
if($_POST["currentPassword"] == $row["password"]) {
mysqli_query($con,"UPDATE student set password='" . $_POST["newPassword"] . "' WHERE name='" . $name . "'");
$message = "Password Changed Sucessfully";
} else $message = "Current Password is not correct";
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Password Change</title>
</head>
<body>
<h3 align="center">CHANGE PASSWORD</h3>
<div><?php if(isset($message)) { echo $message; } ?></div>
<form method="post" action="" align="center">
Current Password:<br>
<input type="password" name="currentPassword"><span id="currentPassword" class="required"></span>
<br>
New Password:<br>
<input type="password" name="newPassword"><span id="newPassword" class="required"></span>
<br>
Confirm Password:<br>
<input type="password" name="confirmPassword"><span id="confirmPassword" class="required"></span>
<br><br>
<input type="submit">
</form>
<br>
<br>
</body>
</html>






Subscribe with us to get latest topic update






Choose a Language



Subscribe