kevin_it Posted August 2, 2006 Share Posted August 2, 2006 I have built a php page that will allow a user to change their password and it works great. What I would like to accomplish now is to compare the "New Password" field (newpassword) and the "Confirm Password" field (confpass) to make sure they are both the same.What would be the commands to do this. I am a "just climbed out of the n00b status".:)Thanks everyone.Kevin Quote Link to comment Share on other sites More sharing options...
BillyBoB Posted August 2, 2006 Share Posted August 2, 2006 ok well the answer would be ...make a form with both new pass old pass and confpass then use this if statment[code]if($newpass==$confpass){//success whatever u do here}else{echo("Your passwords don't match!");}[/code] Quote Link to comment Share on other sites More sharing options...
tomfmason Posted August 2, 2006 Share Posted August 2, 2006 Billy bob is right. I personaly don't like placeing my sucess code before the error code. So I do this[code=php:0]if ($newpass !== $confpass) { echo "Your passwords do not match"; include("yourform.php"); exit;}/*Now you can place your success code below here and wont have to worry about closing the } or rembering to put in your error code at the end of the file. */[/code] Quote Link to comment Share on other sites More sharing options...
onlyican Posted August 2, 2006 Share Posted August 2, 2006 Is there any good reason behind making errors first, or just personal choiceI personally like having the main code in the middle, then the errors down the bottom, cutting off one by one Quote Link to comment Share on other sites More sharing options...
tomfmason Posted August 3, 2006 Share Posted August 3, 2006 I guess that it would be a personal choice. Well also it is a lot cleaner looking and is a little easier to trouble shoot. For instance ,if you do it the way BillyBob suggested, say you have some more if statements it would realy be easy to forget a } along the line. Here is a simple example, say in the eample that you are also going to check to make sure the user is logged in.[code=php:0]session_start();if (!$_SESSION['username']) { echo "Your session error message";}else{ if($newpass==$confpass){ $sql = "";//a sql query to update passwords. if (!$sql) { echo "a error message"; }//it would be realy easy to forget one of these somewhere along the lines //some more code here }else{ echo("Your passwords don't match!"); }}[/code]Where as if you do it the way that I do it would look like this.[code=php:0]if (!$_SESSION['username']) { echo "Your error message"; include("your_login.php"); exit;}if ($newpass !== $confpass) { echo "Your passwords do not match"; include("yourform.php"); exit;}$sql = "";//a sql query to update passwordsif (!sql) { echo "Your sql error message";}//somemore code here[/code]As you can see this is the samething but with one major difference. The layout is alot easier to trouble shoot any problems.Tom Quote Link to comment Share on other sites More sharing options...
onlyican Posted August 3, 2006 Share Posted August 3, 2006 I think as long as you go one way, Errors inside or out, its okSome scripts I seen are all other the placeif(this is good){if(this is wrong){}else{}}else{} Quote Link to comment Share on other sites More sharing options...
redarrow Posted August 3, 2006 Share Posted August 3, 2006 Just done this for you hope it helps good luck.recover password via email.[code]<?phpsession_start();$db=mysql_connect("localhost","xxx","xxxx");mysql_select_db("xxxx",$db);if(!$email=="none"){echo "<html><body vlink='black' alink='black' link='black'><br><br><br><table bordercolor='black'border='4' align='center'><td align='center'><h1><font color='red'>whatever! </font> <h1>valadation Warning!</h1></td></table><br><br><br><div align='center'><font color='red'><b>Sorry please fill in all the form.</b></font> <br> <br> <a href='lostpassword.php'><b>Please try agin!</b> </a><br><br><br><br><br><br><br><br><br><br><br><br><br><hr color='black'><font color='red'>((c))Admin@whatever.com --whatever! --</font><hr color='black'></hr></body></html></div>";exit;}$password=($_POST['password']);$email=($_POST['email']);$query="select * from members where email='$email'";$result=mysql_query($query);if(!mysql_num_rows($result)) {echo "<html><body vlink='black' alink='black' link='black'><br><br><br><table bordercolor='black'border='4' align='center'><td align='center'><h1><font color='red'>Blob it! </font> <h1>valadation Warning!</h1></td></table><br><br><br><div align='center'><font color='red'><b>Sorry there no account for the email address $email!.</b></font> <br> <br> <a href='lostpassword.php'><b>Please try agin!</b> </a><br><br><br><br><br><br><br><br><br><br><br><br><br><hr color='black'><font color='red'>((c))Admin@whay ever.com --whatever! --</font><hr color='black'></hr></body></html></div>";exit;}else{while($record=mysql_fetch_assoc($result)){$pass=$_SESSION['pass']=$record['password'];$to = $email;$subject = 'Password recovery!';$message = "<html><body vlink='black' alink='black' link='black'><br><br><br><table bordercolor='black'border='4' align='center'><td align='center'><h1><font color='red'>Blob it! </font> <h1>Password recovery notice!</h1></td></table><br><br><br><div align='center'><font color='red'><b><h3>Your password is: $pass<br>Please use the link below to login thank you.</b></font> <br> <br></h3> <a href='http://xxxxxxxx.com/login.php'>Login know!</a></a><br><br><br><br><br><br><br><br><br><br><br><br><br><hr color='black'><font color='red'>((c))Admin@whatever.com --website name! --</font><hr color='black'></hr></body></html></div>";$headers = "From: Do not email back\r\n" . 'X-Mailer: PHP/' . phpversion() . "\r\n" . "MIME-Version: 1.0\r\n" . "Content-Type: text/html; charset=utf-8\r\n" . "Content-Transfer-Encoding: 8bit\r\n\r\n";mail($to, $subject, $message, $headers);echo "<html><body vlink='black' alink='black' link='black'><br><br><br><table bordercolor='black'border='4' align='center'><td align='center'><h1><font color='red'>Blob it! </font></h1> <h1>Password recovery</h1> <a href='see.php'>Home</a></td></table><br><br><br><div align='center'><font color='red'><b>Please goto your email account and get your password!</b></font> <br> <br><br><br><br><br><br><br><br><br><br><br><br><br><br><hr color='black'><font color='red'>((c))Admin@whatever.com --whatever.com --</font><hr color='black'></hr></body></html></div>";exit;} }?>[/code] Quote Link to comment Share on other sites More sharing options...
kevin_it Posted August 3, 2006 Author Share Posted August 3, 2006 Thank you very much everyone. I really appreciate it. Like I said, I have tore off my n00b skin and am getting better with PHP. Still a lot to learn, but with great healp like this I can keep myself on the right track.Thank again all!!A+++++++Kevin Quote Link to comment Share on other sites More sharing options...
onlyican Posted August 3, 2006 Share Posted August 3, 2006 You are always learningWHen you stop learning, thats when it becomes boring Quote Link to comment Share on other sites More sharing options...
Liquid Fire Posted August 4, 2006 Share Posted August 4, 2006 if you want to get real fancy you can try to use AJAX. with AJAX i am pretty sure you can have it so that they can't sumbit untill the passwrod match or at least have soem red text the will go away ro green when the password matched or something like that. Quote Link to comment 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.