0

im working on a password verification(php) form when the user
wants to change his/her password.
new password will be typed twice for confirmation.

if the passwords didn't match, a message box will appear (javascript).

it already worked but my problem is when that message box appears,
all the other fields in the form other than the password field becomes blank.
those fields came from a query which is done upon loging in based on
a field from the previous form.

i think after that message box appear, the result of the query becomes 0.

any help will be appreciated.
thanks in advance!

3
Contributors
5
Replies
7
Views
5 Years
Discussion Span
Last Post by newbie26
0
$user = $_POST['username'];     //from previous form after logging in

// this is the query 
$resultwelcome = mysql_query("SELECT * FROM list_table WHERE empnum = '$empid'") or die(mysql_error());
            while($row = mysql_fetch_array($resultwelcome))
            {
                $fname = $row['fcEmpFName'];
                $lname = $row['fcEmpLName'];
                $mname = $row['fcEmpMName'];
            }

//display the name in the change_pass form
Welcome <?php echo 
                                "$lname". ",". " $fname" ;?>,

<form action="change_pass.php"  method="POST">
<input type = "text" name = "usern" size = "20"> <br>
<input type = "password" name = "newpass" size = "20"> <br>
<input type = "password" name = "newpass1" size = "20"> <br>
<input type = "submit" name = "submit" value = "Save Changes">

</form>

<?php
$user=$_POST['usern'];
$newpass=$_POST['newpass'];
$newpass2=$_POST['newpass1'];
$submit=$_POST['submit'];

if ($submit=='Save Changes') {
    if ($newpass == '' || $newpass2 == '')
    {
        echo "<script>alert('Please complete the information!')</script>";    }
    else
    {
        if ($newpass == $newpass2) {
            mysql_query("UPDATE list_table SET userPassWord ='$newpass' WHERE userName='$user'") or die(mysql_error());
            echo "<script>alert('New Password already saved!')</script>";

        }else{
        //when password didnt match, there will be nothing to be displayed in the "welcome,... " part.
            echo "<script>alert('Passwords did not match!')</script>";

        }
    }
}
?>

Edited by Nick Evan: Fixed formatting

0

Well, you could just use PHP to display the message.

if($newpass == $newpass2) {
//do the query
}
else {
echo "Passwords do not match!";
}
0

Well, you could just use PHP to display the message.

if($newpass == $newpass2) {
//do the query
}
else {
echo "Passwords do not match!";
}

thanks for the suggestion..

but i already tried that one..
there was nothing displayed also in the "welcome part.." :-(

0

just created a boolean type table field in the database and get that record when it is true,
all the details will be displayed

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.