Jump to content
Larry Ullman's Book Forums

Chapter 8 Pursue #3 Question


Recommended Posts

"Rewrite the password conditionals found in register.php as a nested pair of conditionals."
 
Why do the password conditionals need to be rewritten to be as a nested pair of conditionals when the un-nested conditionals seemed to be the simpler solution?  I'm not even sure if the solution I came up with is the right one.
 
Original un-nested password conditionals:
 
 if (empty($_POST['password1'])) {
        $problem = true;
        print '<p class="text--error">Please enter a password!</p>';
    }
    
    if ($_POST['password1'] != $_POST['password2']) {
        $problem = true;
        print '<p class="text--error">Your password did not match your confirmed password!</p>';
    }
 
Here's what I have:
 
if ( (empty($_POST['password1'])) OR (empty($_POST['password2'])) OR ($_POST['password1'] != $_POST['password2']) ) { #nest password conditionals
            if ( empty($_POST['password1']) OR (empty($_POST['password2'])) ) {
                print '<p class="text--error">Please enter a password and/or confirm your password!</p>';
            }
            if ($_POST['password1'] != $_POST['password2']) {
                print '<p class="text--error">Your password did not match your confirmed password!</p>';
            }
        $problem = true;
    }

 

Am I on the right track or am I over complicating things?

Link to comment
Share on other sites

  • 3 weeks later...

Sorry for the delayed reply! Yes, you are overcomplicating things, but that's okay. As a tip, the conditions can stay the same as they were, but your two if conditionals change. Let me know if you need more information than that!

Link to comment
Share on other sites

 Share

×
×
  • Create New...