New to PHP
Password change fails please advice
CREATE TABLE IF NOT EXISTS `ps_users` (
`id` int(255) unsigned NOT NULL AUTO_INCREMENT,
`username` varchar(100) NOT NULL,
`firstname` varchar(50) DEFAULT NULL,
`lastname` varchar(50) DEFAULT NULL,
`password` varchar(40) NOT NULL,
`active` int(1) NOT NULL DEFAULT '0',
`ip` text NOT NULL,
`usergroup` text NOT NULL,
`datasource_id` int(3) unsigned DEFAULT '0',
`last_login` int(14) DEFAULT NULL,
`day_limit` int(3) unsigned DEFAULT NULL,
`language` varchar(5) NOT NULL DEFAULT 'en',
`email` varchar(100) DEFAULT NULL,
`pwd_updated` int(14) unsigned DEFAULT NULL,
`created` int(14) unsigned NOT NULL DEFAULT '0',
`owner_id` int(255) NOT NULL DEFAULT '0',
`modified` int(14) unsigned DEFAULT NULL,
`updated` int(14) unsigned DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `login` (`username`),
KEY `active` (`active`),
KEY `password` (`password`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=11 ;
<html>
<head>
</head>
<body bgcolor="#5791BF">
<h1>Change Password</h1>
<form method="POST" action="passch.php">
<table>
<tr>
<td>Enter your UserName</td>
<td><input type="username" size="10" name="username"></td>
<td>Enter your existing password:</td>
<td><input type="password" size="10" name="password"></td>
</tr>
<tr>
<td>Enter your new password:</td>
<td><input type="password" size="10" name="newpassword"></td>
</tr>
</table>
<p><input type="submit" value="Update Password">
</form>
<p><a href="member-index.php">Home</a>
<p><a href="logout.php">Logout</a>
</body>
</html>
<?php
$server="localhost";
$db_user="root";
$db_pass="brijpuja1";
$database="puresearch";
// connect to the mysql server
$link = mysql_connect($server, $db_user, $db_pass)
or die ("Could not connect to mysql because ".mysql_error());
// select the database
mysql_select_db($database)
or die ("Could not select database because ".mysql_error());
$rs_pwd = mysql_query("select password FROM ps_users where username='$_POST[username]'");
list($old) = mysql_fetch_row($rs_pwd);
if($old == md5($_POST['password']))
{
$newmd5 = md5(mysql_real_escape_string($_POST['newpassword']));
mysql_query("update ps_users set password='$newmd5' where username='$_POST[username]'");
echo "Password Changed successfully";
} else
{
echo "Password change failed";
}
?>