Tandem Posted July 17, 2006 Share Posted July 17, 2006 I'm writing a script so that members can change their passwords.I'm starting the script by checking the form for errors. The first error i'm checking for is empty fields. This below script does this semi-successfully. It prints out that an error has occurred and what the errors are depending on which field is empty. The problem is that it always prints out that there has been an error, even if all the feilds have been filled in.[code]<?phpsession_start();include 'db.php';include 'session_check.php';$current_pass = $_POST['current_pass'];$new_pass = $_POST['new_pass'];$confirm_pass = $_POST['confirm_pass'];//Checking for empty fieldsif ((empty($current_pass)) || (empty($new_pass)) || (empty($confrim_pass))) {echo '<div class="error">*The following errors occurred:</div>' . "\n";if (empty($current_pass)) {echo '<div class="error">You did not specify your Current Password</div>' . "\n";}if (empty($new_pass)) {echo '<div class="error">You did not specify your New Password</div>' . "\n";}if (empty($confirm_pass)) {echo '<div class="error">You did not Confirm your New Password</div>' . "\n";}include 'Account_Manager.php';exit();}?>[/code]Can any tell me why, and how to fix it?Thanks in advance.-Tandem Link to comment https://forums.phpfreaks.com/topic/14835-not-sure-why/ Share on other sites More sharing options...
brown2005 Posted July 17, 2006 Share Posted July 17, 2006 if((!$username) || (!$password) || (!$number)){ if(!$username) { $error .= "<tr><td>You have not entered your username.</td></tr>"; } if(!$password) { $error .= "<tr><td>You have not entered your password.</td></tr>"; } if(!$number) { $error .= "<tr><td>You have not entered the verification code.</td></tr>"; } }try that mate, it is wat i use Link to comment https://forums.phpfreaks.com/topic/14835-not-sure-why/#findComment-59281 Share on other sites More sharing options...
obsidian Posted July 17, 2006 Share Posted July 17, 2006 the only problem with that code, brown2005, is that it will throw warnings whenever your form is not submitted yet. you can't refer directly to the variables without checking to see if they are set yet.the best bet is to do something like this:[code]<?phpif (isset($_POST['submit'])) { foreach ($_POST as $key => $val) ${$key} = trim($val); if (empty($current_pass) || empty($new_pass) || empty($confirm_pass)) { echo "<div class=\"error\">The following error has occurred:</div>\n"; if (empty($current_pass)) echo '<div class="error">You did not specify your Current Password</div>' . "\n"; if (empty($new_pass)) echo '<div class="error">You did not specify your New password</div>' . "\n"; if (empty($confirm_pass)) echo '<div class="error">You did not Confirm your New Password</div>' . "\n"; }}?>[/code]hope this helps Link to comment https://forums.phpfreaks.com/topic/14835-not-sure-why/#findComment-59285 Share on other sites More sharing options...
hvle Posted July 17, 2006 Share Posted July 17, 2006 you got a mis-spelling in var name:empty($confrim_pass) from the if statement,change to $confirm from $confrim Link to comment https://forums.phpfreaks.com/topic/14835-not-sure-why/#findComment-59286 Share on other sites More sharing options...
Tandem Posted July 17, 2006 Author Share Posted July 17, 2006 Ahhh, thankyou hvle. Link to comment https://forums.phpfreaks.com/topic/14835-not-sure-why/#findComment-59288 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.