i have made a change password script in PHP and it isnt working
<p>I have the following code, and it will not work. I am currently working on a simple change password feature for a system and cant get it to function correctly. i was wondering if i was overlooking a really simple solution?</p>

<pre><code>&lt;?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!";
    }

  ?&gt;
</code></pre>
