I have my php page, in which i have 3 fields old pass, new pass, confirm new pass. I'm trying to chnge the password of my id from which i am logged in. The program first check in the database and change the password of the logged in user. I have tried a code for it. But whenever i fill all the fields and click DONE. It just refreshes the page and nothing happens, no changing in the database and no message is displayed on the page. Can some one find out the problem?
Thanks in ADVANCE.
<?php session_start();
?>
<?php include_once("../includes/connection.php"); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Example form</title>
<style type="text/css">
.container1 {
width: 500px;
clear: both;
}
.container1 input {
width: 100%;
clear: both;
}
</style>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="style.css" />
<title>Change Password</title>
</head>
<body>
<div id="container">
<div id="header">
<h1 style="text-align:left">Quality Management<span class="off"> Cell</span></h1>
</div>
<div id="menu">
<ul>
<li class="menuitem"><a href="cms.php">Home</a></li>
<li class="menuitem"><a href="cms-attendance.php">Attendance</a></li>
<li class="menuitem"><a href="cms-courses.php">Courses</a></li>
<li class="menuitem"><a href="cms-settings.php">Settings</a></li>
</ul>
<a style="text-align:right" href="cms-logout.php">Logout</a>
</div>
</div>
<div id="content" align="justify">
<div id="content_top"></div>
<div id="content_main">
<div id="wrapper">
<form class="login-form" method ="post" action="">
<label for="password">Old Password:</label>
<input name="old_password"/><br /><br />
<label for="password">New Password:</label>
<input name="n_password"/><br /><br />
<label for="password">Confirm new Password:</label>
<input name="new_password"/><br />
<p>
<br />
<input class="button" name="submit" type="Submit" value="Done"/>
</form>
<?php
if(isset($_POST['old_password']) && isset($_POST['password']) && isset($_POST['new_password'])){
$old_pass = $_POST['old_password'];
$password = $_POST['n_password'];
$new_pass = $_POST['new_password'];
if (isset($_SESSION['user_name'])){
$username = $_SESSION['user_name'];
$query_pass = "SELECT user_pass FROM users WHERE user_name = '".$_SESSION['user_name']."'";
$result_set = mysql_query($query_pass) or die(mysql_error());
$pass_rows = mysql_affected_rows($result_set) or die (mysql_error());
$pass_set = mysql_fetch_array($pass_rows);
while ($pass_set = mysql_fetch_array($result_set)){
$pass_set['user_id'];
$pass_set['user_name'];
$pass_set['user_pass'];
if(empty($old_pass)|| empty($password)|| empty($new_pass)){
echo "ALL THE FIELDS ARE REQUIRED";
}
else if ($pass_set['user_pass']!=$old_pass){
echo "PASSWORD DID'NT MATCH!";
}
else if ($password != $new_pass){
echo "NEW PASS DID'NT MATCH!";
}
else if ($new_pass == $old_pass){
echo "CAN NOT MATCH THE OLD PASSWORD";
}
else {
$change_pass = "UPDATE users SET user_pass = '".$new_pass."' WHERE user_name = '".$_SESSION['user_name']."'";
$pass_query = mysql_query($change_pass) or die (mysql_error());
if ($pass_query){
echo "Password Changed";
}
else {
echo "Invalid";
}
}
}}
}
?>
<p> </p>
<p> </p>
<div id="content_bottom"></div>
</div>
</div>
</body>
</html>