JasonHegarty Posted July 1, 2012 Share Posted July 1, 2012 (edited) Hi first time post - just got the book a couple of days ago - the book is great! Struggling to understand this though.. Step six asks you to write this script: //check comments were entered. if (!empty($_REQUEST['comments'])){ $comments = $_REQUEST['comments']; } else { $comments = NULL; echo '<p class ="error">What you don\'t want to comment afterall?</p>'; } //validate gender variable. 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>'; } Why would you create $greeting which is different depending on the answer stored in the $gender when echo would do? Am I missing something here? Also its the first time $greeting has been mentioned in this script and I can't see it referenced elsewhere which up until this point when a new variable has been introduced the book has explained what it is storing or doing. Help! One other thing - if the user writes in the comments box the following: 'I didn't realise it was Sunday today' it is output after successful submission as 'I didn\'t realsie is was Sunday today' Anyway to fix this so that the \ isn't output? Edited July 1, 2012 by JasonHegarty Link to comment Share on other sites More sharing options...
margaux Posted July 1, 2012 Share Posted July 1, 2012 Regarding your second question, your system probably has magic quotes turned on. You can look up magic quotes in the php manual - even though it is deprecated, a lot of hosts keep it enabled. To override it you can check for it and then use stripslashes() e.g. $comments = (get_magic_quotes_gpc() ? stripslashes($_REQUEST['comments']) : $_REQUEST['comments']); 2 Link to comment Share on other sites More sharing options...
JasonHegarty Posted July 1, 2012 Author Share Posted July 1, 2012 Regarding your second question, your system probably has magic quotes turned on. You can look up magic quotes in the php manual - even though it is deprecated, a lot of hosts keep it enabled. To override it you can check for it and then use stripslashes() e.g. $comments = (get_magic_quotes_gpc() ? stripslashes($_REQUEST['comments']) : $_REQUEST['comments']); Thanks for this margaux worked a treat! Link to comment Share on other sites More sharing options...
Larry Posted July 1, 2012 Share Posted July 1, 2012 Thanks for the nice words, Jason. And thanks Margaux for helping! Link to comment Share on other sites More sharing options...
Recommended Posts