Jump to content
Larry Ullman's Book Forums

tjserb

Members
  • Posts

    1
  • Joined

  • Last visited

tjserb's Achievements

Newbie

Newbie (1/14)

0

Reputation

  1. I just started going through the book and ran into my first problem while working through the end of chapter 2 in the Pursue section: The relevant part of Script 2.4 is: if (isset($_POST['gender'])) { $gender = $_POST['gender']; if ($gender == 'M') { echo '<p><b>Good day, Sir!</b></p>'; } elseif ($gender == 'F') { echo '<p><b>Good day, Madam!</b></p>'; } else { $gender = NULL; echo '<p class="error"><b>Gender should be either M or F!</b></p>'; } } else { $gender = NULL; echo '<p class="error"><b>You forgot to select your gender!</b></p>'; } I am using 'yes' and 'no' instead of 'M' and 'F' but this is the code that I used: if(isset($_POST['newsletter']) == 'yes') { echo "<p>Thank you for signing up for our monthly newsletter!</p>"; } elseif(isset($_POST['newsletter']) == 'no') { echo "<p>We are sorry you have decided NOT to sign up for our newsletter.</p>"; } else { echo "<p>You for got to choose a newsletter option!</p>"; } I know the hint suggested that I use the AND operator. The above code seems like it should work but ifelse(or the 'no') is printing the same as the if(or the 'yes') response and the else(where nothing is checked) is printing the correct response. In other words, When no is checked on the form it is saying "thank you for signing up" instead of "sorry you have decided to NOT..."
×
×
  • Create New...