Jump to content

Recommended Posts

hi all,

 

i am trying to get some form of authentication for a website.  I have managed to get a form done and it asks you to put in a password twice, the reason being i want to check the both passwords entered are the same. 

 

here is how i am checking the passwords,for now the form is simply posted to another file as i don't know any other way to do it.

 

how can i get to return to the original form with the error message from the else statement displayed as to why you have been returned ?

 

if ($_POST["Password1"] == $_POST["Password2"] )
  {
                $Password1 = $_POST['Password1'];
	echo "hello $Password1";  
   
  }
else
  {
        echo "Your Passwords do not match ! please re-submit";
  }

 

 

Thanks for any help you can give

 

Sudsy

Link to comment
https://forums.phpfreaks.com/topic/131939-solved-comparing-form-values/
Share on other sites

<?php
  $str='Enter the password';
  $pass1=$_POST['password1'];
  $pass2=$_POST['password2'];
  if ($_POST['subdoit']) {
    if ($pass1==$pass2) {
      $msg='Password matches';
    } else {
      $msg='Password incorrect';
    }
  }
?>
<html>
<head>
  <title>Test Script</title>
</head>
<body>
  <?=$msg?><br /><br />
  <form action="<?=$_SERVER['PHP_SELF']?>" method="post">
  Password 1: <input type="password" name="password1" /><br />
  Password 2: <input type="password" name="password2" /><br />
  <input type="submit" name="subdoit" value="Check Passwords" />
  </form>
</body>
</html>

 

Just knocked that up, not checked, should work though. If you want to redirect do a different script just replace the $msg=''; lines in if() with this:

header("Location: newfile.php");
exit;

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.