我有以下代码,它不起作用。我目前正在为系统开发一个简单的更改密码功能,但无法使其正常运行。我想知道我是否忽略了一个非常简单的解决方案?
<?php
$con = mysql_connect("localhost","root");
if (!$con) {
die('Could not connect: ' . mysql_error());
}
$username = $_POST['userid'];
$password = $_POST['cpword'];
$newpassword = $_POST['pword'];
$confirmnewpassword = $_POST['pword2'];
$result = mysql_query("SELECT username, pword FROM login WHERE username='$username'");
if(!$result) {
echo "The username entered does not exist!";
} else
if($password != mysql_result($result, 0)) {
echo "Entered an incorrect password";
}
if($newpassword == $confirmnewpassword) {
$sql = mysql_query("UPDATE login SET pword = '$newpassword' WHERE username = '$username'");
}
if(!$sql) {
echo "Congratulations, password successfully changed!";
} else {
echo "New password and confirm password must be the same!";
}
?>