perry Posted December 25, 2011 Share Posted December 25, 2011 I'm hoping for some kind assistance for this old brain. I'm trying to change the cliché "You can't teach an old dog new tricks"... OK, I understand creating of the $okay flag variable as TRUE and then the introduction of the empty() function with if (empty($_POST['email'])) {print '<p class="error"> Please enter your email address.</p>'; $okay = FALSE. But what I don't understand is if the user does not enter the necessary information and then the $okay value changes to FALSE, what keeps the success message from printing? So the flag variable has changed from TRUE to FALSE, how does that make the success message not print? To quote the book "In that case, this conditional will also be FALSE so the message won't be printed". Obviously it works, I'm just not getting why... Any help would be much appreciated. Perry Link to comment Share on other sites More sharing options...
timpearson26 Posted December 26, 2011 Share Posted December 26, 2011 Can you give the page number in the book your referring to. If I remember, I think that form validation is all part of an 'if' conditional. So if $okay = FALSE then the the conditional will be false and the success message won't print. Not sure if thats correct or not, I'm sure you'll get more clarification when you give the page number. Tim Link to comment Share on other sites More sharing options...
perry Posted December 26, 2011 Author Share Posted December 26, 2011 Mr. Pearson, First it's on pages 120 and 121. So, if I understand correctly, after creating the flag variable $okay = TRUE; (page 120) the script will always print the success message until the if empty() Validation Function is introduced on page 122 which will then cause the $okay flag variable to change to FALSE. That I understand but why will then the success message not print? if ($okay) { print '<p>You have been successfully registered (but not really).</p>; What's the connection of $okay now being FALSE to the nonprinting of the message? Thanks so much for all your help!!! Perry Link to comment Share on other sites More sharing options...
Jonathon Posted December 26, 2011 Share Posted December 26, 2011 if $okay = FALSE; then the query if ($okay) basically means (Although not technically) does $okay exist? as its FALSE the answer is no. So there will be no message printed. 1 Link to comment Share on other sites More sharing options...
timpearson26 Posted December 27, 2011 Share Posted December 27, 2011 What's the connection of $okay now being FALSE to the nonprinting of the message? Thanks so much for all your help!!! Do you understand how the 'if' conditional works? When writing the 'if' conditional, if whatever is in the parentheses is TRUE, the following lines of code will be executed. But if whatever is in the parentheses is FALSE, the following lines of code will not be executed. For example: if (1 == 1) { print '<p>You have been successfully registered (but not really).</p>'; } (this above example will print) but this example: if (1 == 2) { print '<p>You have been successfully registered (but not really).</p>'; } this will not print because, obviously, 1 does not equal 2. So in the code on page 123. You see on line 20 the flag variable is created and is given the value of TURE. At this point if everything goes good, the success message will print. BUT, before the success message prints, you first have to get past the other 2 'if' statements. Those 'if' statements validate the email and password. If either one of those 'if' statements has a value of TRUE (in other words, if either the $_POST['email'] or the $_POST['password'] is empty), then the code below those 'if' statements execute. And both of those validation 'if' statements do 2 things. First, they print an error message, and 2nd, they change the value of $okay to the value of FALSE. If that happens, you will not see the success message because now: if ($okay) { ...} has the value of if (FALSE) { //therefor nothing happens } Hopefully that makes it a little more clear. Tim 1 Link to comment Share on other sites More sharing options...
perry Posted December 27, 2011 Author Share Posted December 27, 2011 Mr. Pearson, That is EXTREMELY helpful... Thank you so much for spending the time to help me! Perry Link to comment Share on other sites More sharing options...
timpearson26 Posted December 27, 2011 Share Posted December 27, 2011 Mr. Pearson, That is EXTREMELY helpful... Thank you so much for spending the time to help me! Perry Sure no prob. Glad it helped. Tim Link to comment Share on other sites More sharing options...
Recommended Posts