Jump to content
Larry Ullman's Book Forums

Recommended Posts

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

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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.

  • Upvote 1

Share this post


Link to post
Share on other sites

 

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

  • Upvote 1

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

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...
Sign in to follow this  

×
×
  • Create New...