Change Password Using PHP and MySQL.
If user wants to change their password then put update query of MySQL using PHP webpage scripting.
First Step to check weather user had input their old password, new password and confirm new password.
If not then give error message using PHP script.
After that check database connection and write query to update oldpass with newpass.
Here is the full code to change your password using PHP + MySQL.
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title> Change Password </title>
<?php
if(isset($_POST['submit']))
{
include('dbconn.php');
$old=trim($_POST['oldpass']);
$new=trim($_POST['newpass']);
$cnew=trim($_POST['cnewpass']);
if(empty($old))
{
echo "<p style='color:red;'> Please Enter Your Old Password </p>";
}
elseif(empty($new))
{
echo "<p style='color:red;'> Please Enter Desired New Password </p>";
}
elseif(empty($cnew))
{
echo "<p style='color:red;'> Please Enter Confirm New Password </p>";
}
elseif(strcmp($new,$cnew))
{
echo "<p style='color:red'> New Password And Confirm New Password Does Not Match </p>";
}
else
{
$sql="SELECT * FROM tbl_employer_reg WHERE password='$old'";
$result=mysqli_query($con,$sql);
$num_rows=mysqli_num_rows($result);
if($num_rows==1)
{
$sql="UPDATE `tbl_employer_reg` SET `password`= '$new' WHERE `password`= '$old'";
$r=mysqli_query($con,$sql);
echo "<p style='color:red;'> Your Password Has Been Changed</p>";
}
else
{
echo "<p style='color:red;'> Incorrect Password </p>";
}
}
$_POST['oldpass']="";
$_POST['newpass']="";
$_POST['cnewpass']="";
}
?>
</head>
<body>
<div style="width:520px;padding:10px;border:5px solid blue;margin:150px 250px;border-radius:25px;">
<h2 style="color:red"><center> CHANGE PASSWORD </center></h2>
<form name="change_pass" id="change_pass" method="post" action="">
<table border="0" cellpadding="6">
<tr>
<td style="color:#0000FF; font-weight:bolder; font-size:18px;">Enter Old Password : </td>
<td> <input type="password" name="oldpass" value="<?php if(isset($_POST['oldpass'])) {echo $_POST['oldpass'];} ?>" size="40" /></td>
</tr>
<tr>
<td style="color:#0000FF; font-weight:bolder; font-size:18px;">Enter New Password : </td>
<td> <input type="password" name="newpass" value="<?php if(isset($_POST['newpass'])) {echo $_POST['newpass'];} ?>" size="40" /></td>
</tr>
<tr>
<td style="color:#0000FF; font-weight:bolder;font-size:18px;">Confirm New Password : </td>
<td> <input type="password" name="cnewpass" value="<?php if(isset($_POST['cnewpass'])){echo $_POST['cnewpass'];} ?>" size="40" /></td>
</tr>
<tr>
<td> </td>
<td> <input type="submit" name="submit" value="SUBMIT" style="color:#0033FF;background-color:#CCCCCC; font-weight:bolder;font-size:22px" /> </td>
</tr>
</table>
</form>
</div>
</body>
</html>
Learn PHP Project Training
visit website: Project Training Using PHP Technologies
very nice informative post.seo
ReplyDelete