sudsy1970 Posted November 8, 2008 Share Posted November 8, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/131939-solved-comparing-form-values/ Share on other sites More sharing options...
Yesideez Posted November 8, 2008 Share Posted November 8, 2008 <?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; Quote Link to comment https://forums.phpfreaks.com/topic/131939-solved-comparing-form-values/#findComment-685500 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.