[Separate threads merged -- MOD]
Hello,
I'm very new to PHP (just started learning a month ago) and i'm having some trouble. Please excuse me if these questions are simple. I'm pretty stuck.
I'm trying to write code that will allow users to change their password. The way I have it set up is that there's a page called 'changepassword.php' that has the form on it and then there's a page called 'change-passwordck.php' that checks the form. But it doesn't work. When you fill out the form and hit 'submit' the 'change-passwordck' page does come up but it doesn't spit out the message it should and the database does not update.
Here's my code.....
'changepassword.php'
//The following is at the very top of the page:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<? include "include/z_db.php"; ?>
//The following is in the <body>
<table border='0' width='50%' cellspacing='0' cellpadding='0' align=center style="height: 153px"><form name=form2 method=post action=change-passwordck.php onsubmit='return validate(this)'><input type="hidden" name="todo" value="post"/>
<tr ><td bgcolor="#FFFFFF" style="width: 201px" > <font face='Verdana' size='2' color="#000000" ><b>User Name:</b></font></td><td bgcolor="#FFFFFF" ><font face='Verdana' size='2'>
<input type="text" name="userame" size="10" maxlength="20" value="<?php if (isset($POST['username'])) echo $POST['username'];?>" style="width: 132px" />
<tr ><td bgcolor="#FFFFFF" style="width: 201px" > <font face='Verdana' size='2' color="#000000" ><b>Current password:</b></font></td><td bgcolor="#FFFFFF" ><font face='Verdana' size='2'>
<input type="password" name="password" size="20" maxlength="20" style="width: 132px" />
<tr ><td bgcolor="#FFFFFF" style="width: 201px" > <font face='Verdana' size='2' color="#000000" ><b>New password:</b> </font></td><td bgcolor="#FFFFFF" ><font face='Verdana' size='2'>
<input type="password" name="password1" size="20" maxlength="20" style="width: 131px" />
<tr ><td bgcolor="#FFFFFF" style="width: 201px" > <font face='Verdana' size='2' color="#000000" ><b>Confirm New password:</b></font></td><td bgcolor="#FFFFFF" ><font face='Verdana' size='2'>
<input type="password" name="password2" size="20" maxlength="20" style="width: 131px" /><tr ><td bgcolor="#FFFFFF" colspan="2" class="style4" ><font face='Verdana' size='2'> <input type="submit" name="submit" value="Change My password" /></font></td>
</tr></font></td></table>
'change-passwordck.php'
<?
if(isset($todo) and $todo=="changepassword"){
$password=mysql_real_escape_string($password);
//Setting flags for checking
$status = "OK";
$msg="";
if ( strlen($password) < 3 or strlen($password) > 8 ){
$msg=$msg."Password must be more than 3 char legth and maximum 8 char lenght<BR>";
$status= "NOTOK";}
if ( $password <> $password2 ){
$msg=$msg."Both passwords are not matching<BR>";
$status= "NOTOK";}
if($status<>"OK"){
echo "<font face='Verdana' size='2' color=red>$msg</font><br><center><input type='button' value='Retry' onClick='history.go(-1)'></center>";
}else{ // if all validations are passed.
if(mysql_query("UPDATE accounts SET password='$password' WHERE username='$session[username]'")){
echo "<font face='Verdana' size='2' ><center>Thanks <br> Your password has been changed successfully.</font></center>";
}
}
}
echo "<center><font face='Verdana' size='2' ><br><br>Click <a href=logout.php>here to logout</a> | <a href=changepassword.php>Change Password</a><br></center></font>";
?>
Any ideas of what could be preventing this code from working correctly? I've stared at it for so long that I'm useless as far as figuring out how I screwed it up. Thanks in advance for any help you guys can offer.