johnyjharris
-
Posts
3 -
Joined
-
Last visited
Posts posted by johnyjharris
-
-
Many thanks Larry,
I'm afraid to say, I'm still stumped with this, at least that is if i've understood it correctly- I'm reading it as using only one conditional and no nested conditionals.
With one conditional I can only work out how to account for 2 eventualities - either gender being M or F.
if (isset($_REQUEST['gender']) && ($_REQUEST['gender'] == 'M')) { $greeting = '<p><b>Good day, Sir!<b></p>'; } else { $greeting = '<p><b>Good day, Madam!<b></p>'; }
I understand this no good as it does not account for checking isset and setting gender = NULL if the user hasn't selected M or F
-
Hi folks
And thanks Larry for a great book, its quite inspiring. I'm new to programming, I know my HTML and CSS but that's it. I've been following your book and I'm up to Chapter 2 - Review and Pursue and stuck on the third question, sorry if this has been covered already.
Rewrite the gender conditional in handle_form.php (Script2.4) as one conditional instad of two nested ones, Hint: you'll need to use the AND operator.The code in question is
if (isset($_REQUEST['gender'])) { $gender = $_REQUEST['gender']; if ($gender == 'M') { $greeting = '<p><b>Good day, Sir!<b></p>'; } elseif ($gender == 'F') { $greeting = '<p><b>Good day, Madam!<b></p>'; } else { $gender = NULL; echo '<p class="error">Gender should be either "M" or "F"!</p>'; }
I've been stuck all day, I have gone away and come back again and I'm still drawing a blank.
Any help would be really appreciated, thanks.
Review And Pursue
in PHP and MySQL for Dynamic Web Sites: Visual QuickPro Guide (4th Edition)
Posted
I think I had moment of clarity this morning! After re-reading the paragraph about elseif I presume elseif isn't classed as a nested conditional - rather adding a conditional to an existing one.
Anyway I managed it with the following code.