FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


Help! This small script has logical problems. Please help





imagefree
This is a piece of code from my update_profile.php page. It updates the password entered by user.

Code:
else if(isset($_POST['p_submit']))
{
   $password=$_SESSION['password']; // Session already keeps the previous md5ed password.
   $check=md5($_POST['new_password']);
   if(($_POST['new_password']==$_POST['confirm_password']) && $check!=$password)
   {
      $new_password=$_POST['new_password'];
      if(strlen($new_password) >=8  && strlen($new_password) <17)
      {
         $secure_password=md5($new_password);
         $update_query="UPDATE frsh_users SET password = '$secure_password' WHERE username = '$username' ";
         mysql_query($update_query)?    $registeration_success=1 :    $registeration_success=0;
         if($registeration_success)
         {
            $_SESSION['password']=$secure_password;
            $message[]="Records Updated. Password reset.";
         }
         else $errors[]='Problem accured while setting new password. Please try later.';
      }
      else $errors[]='Password length improper. Please try to keep it between 8-16 characters.';
   }
   else $errors[]='No need to update Records. New password is same as old one.';
   //name="new_password";
   //name="confirm_password";
}



Here is the Form tat submittes the value:

Code:
      <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
         <input name="new_password" type="password" class="form_input" size="30" />
         <input name="confirm_pass" type="password" class="form_input" size="30" />
         <input name="p_submit" type="submit" value="Update" />
      </form>



what does it do is just run the last else statement

Code:
else $errors[]='No need to update Records. New password is same as old one.';



Where is tehe problem. Please help me.

Thanks
erlendhg
Hi!

I think I can spot your error.

In the php code, you have the line
Code:
if(($_POST['new_password']==$_POST['confirm_password']) && $check!=$password)


You check the posted variable 'new_password' against 'confirm_password', but 'confirm_password' doesn't exist.

The variable you post from the form is called 'confirm_pass'.

Hence the if test will return false, and the error message you mentioned is displayed.

Good luck with your script Wink
sonam
I am not sure but I think how if statment must start with if not with else if. Try to change your
Code:
else if(isset($_POST['p_submit']))

in
Code:
if(isset($_POST['p_submit']))


Sonam
rvec
I would suggest making if elseif and else code like this:
Code:

if (....) {
    some code
} elseif (......) {
    some code
} else {
    if (.....) {
        some code
    }
}

it makes it a bit easier to read than leaving {} away half of the times
imagefree
erlendhg wrote:
Hi!

I think I can spot your error.

In the php code, you have the line
Code:
if(($_POST['new_password']==$_POST['confirm_password']) && $check!=$password)


You check the posted variable 'new_password' against 'confirm_password', but 'confirm_password' doesn't exist.

The variable you post from the form is called 'confirm_pass'.

Hence the if test will return false, and the error message you mentioned is displayed.

Good luck with your script Wink



OOOOOOOOOOPS

Thanks! Was really confused.


@sonam Actually its the piece of code copied from a whole page and i copied just the relevent part.


Thanks to RVEC.
Related topics
How To : Improve Your PHP Programming
help me plzzz
Help with upload form script! [RESOLVED]
Help me find please
Database Privilege
PHP script installation for $4 or FRIH$ 30 (Worth $1000)
Please help. php script installation error
Small script wanted
perl help... script almost working... please help..
Help with Creating New Website Please?
Help with Creating New Website Please?
how to put what you have query in a drop down list?
IE problems.. PLEASE HELP!!
Please help about this..
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.