Some tips on debugging:
If you've collected the errors in an array, might as well check to see if there are any errors:
PHP Code:
var_dump($errors);
then, there could also be a possibility that there is something wrong with your HTML form. (I having a similar problem, which took me a good amount of time to find out that I had made a mistake in the <form> tag).
Check if you are actually getting variables from $_POST:
PHP Code:
var_dump($_POST);
var_dump is quite a useful tool for debugging.
Finally, coming to your specific issue:
PHP Code:
//...
if(empty($errors)){
//This part will be executed if there aren't any errors
$query = "SELECT user_id FROM users WHERE(user_name='$username' AND pass=SHA1('$pass'))";
$result = mysql_query($query);
$num = mysql_num_rows($result) OR die(mysql_error());
// If there are no errors, no more code will be executed.
}else{
// Notice! This is in "else". That means that this part (and not the part below "if (empty($errors)){..." will be executed if there *are* errors.
// Maybe you didn't want this "else" line here. Try moving it to the bottom
if($num == 1){
$row = mysqli_fetch_array($result, MYSQL_NUM);
$sql = "UPDATE users SET pass = SHA1('$new_pass') WHERE user_id = $row[0]";
$r = mysql_query($sql);
if(mysql_affected_rows($con) == 1){
echo '<h1>Thank You</h1><br /><p>Your password has now been changed</p>';
}else{
echo '<h1>Sorry</h1><br /><p>Your password cannot be changed because of a system error</p>';
}
}else{
echo "Your username and password don't match the ones on file.";
}
// Try moving "else" here and do something like:
//else{
//var_dump($errors);
//}