Hello everyone! I am currently working on a change password code. I am having trouble because everytime I click submit the page seems to simply refresh. I am new to php and I am sure that everything on the database side is working alright. I have a working login, registration, etc. The only thing that doesn't work is the change password. I would appreciate any and all help! Thank you!
<html>
<head>
<title>Change Password</title>
<link rel="stylesheet" type="text/css" href="style.css" />
</head>
<body>
<?php
$connection=mysql_connect('localhost','root','') or die (mysql_error());
$db=mysql_select_db('loginTut',$connection) or die (mysql_error());
$username = $_POST['username'];
$password = $_POST['password'];
$newpassword = $_POST['newpassword'];
$newpassword = md5($newpassword);
$confirmnewpassword = $_POST['confirmnewpassword'];
$confirmnewpassword = md5($confirmnewpassword);
$result = mysql_query("SELECT count(*) FROM users WHERE username='$username' and password='".md5($password)."'");
if(mysql_result($result,0)==1) //there must be one combination of user/pass
{
if($newpassword==$confirmnewpassword)
{
$sql=mysql_query("UPDATE users SET password='$newpassword' where username='$username'");
if($sql)
{
echo "Congratulations! You have successfully changed your password";
}
}
else
{
echo "The new password and confirm new password fields must be the same";
}
}
else
{
echo "Invalid Username/Password";
}
?>
<form action="changepassword.php" method="post">
<div id="border">
<table cellpadding="2" cellspacing="0" border="0">
<tr>
<td align="center" colspan="2">Change your password by entering the necessary information below:</td>
</tr>
<tr>
<td>Username:</td>
<td><input type="text" name="username" /></td>
</tr>
<tr>
<td>Password:</td>
<td><input type="password" name="password" /></td>
</tr>
<tr>
<td>New Password:</td>
<td><input type="password" name="newpassword" /></td>
</tr>
<tr>
<td>Confirm New Password:</td>
<td><input type="password" name="confirmnewpassword" /></td>
</tr>
<tr>
<td align="center" colspan="2"><input type="submit" name="submit" value="Submit" /></td>
</tr>
</table>
</div>
</form>
</body>
</html>