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...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  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.

Loading...
 Share

×
×
  • Create New...