User wants to change old pass to new
<p>Hello I have project that is due tonight and I have been working on this whole thing for awhile, but I cannot seem to get this code to work (this is just a snippet of it) so I'm not sure as to why, I think it can read the user but not the pass so I'm not sure as to what is wrong with my code here Any help that is given would greatly be appreciated:    </p>

<pre><code>&lt;?php
if(isset($_POST['change-submit']))
{
if (isset($_POST['username']) &amp;&amp; isset($_POST['oldPassword']) &amp;&amp; isset($_POST['newPassword'])
&amp;&amp; isset($_POST['newPasswordck']))
{
$username = $_POST['username'];
$old_pw = $_POST['oldPassword'];
$new_pw = $_POST['newPassword'];
$password2 = $_POST['newPasswordck'];

$r = mysql_query("SELECT user_id FROM user WHERE user_name='$username' AND password='$password'");
if(mysql_num_rows($r)&gt;0)
{
$d = mysql_fetch_array($r);
}
if($new_pw == $password2 &amp;&amp; $new_pw != "")
{
$r = mysql_query("UPDATE user SET password = ('$new_pw') WHERE user_name = '$username'");

if(mysql_affected_rows() &gt; 0)
{
echo  "Changes effected.";
}
else
{
echo  "New passwords must match.";
}
if(mysql_affected_rows() &lt; 0)
{
echo  "Your login details do not match any records in the database.";
}
}

 }
 }  
?&gt;
  &lt;form name="newpassord" action="succesfulPasswordChange.html" method="post"&gt;
&lt;h5 align="right" class="website"&gt;Change my password:&lt;/h5&gt;&lt;td&gt;&lt;h5     align="right"class="website"&gt;(Reminder: Passwords are only 8 characters long.)&lt;/td&gt;
&lt;h5 align="right" class="website"&gt;User Name:&lt;input type ="textbox" name="username" /&gt;&lt;/h5&gt;
&lt;h5 align="right" class="website"&gt;Old password:&lt;input type ="textbox" name="oldPassword" /&gt;&lt;/h5&gt;
&lt;h5 align="right"class="website"&gt;New password:&lt;input type ="textbox" name="newPassword" /&gt;&lt;/h5&gt;
&lt;h5 align="right"class="website"&gt;Retype password:&lt;input type ="textbox" name="newPasswordck" /&gt;&lt;/h5&gt;
&lt;div align="right"&gt;&lt;h3 class="website"&gt;&lt;input type = "submit" value = "submit" name="change-submit"/&gt;&lt;input type = "reset" value = "reset"/&gt;&lt;/div&gt;
&lt;/form&gt;
</code></pre>
