Jump to content
Larry Ullman's Book Forums
Sign in to follow this  
hugo

Help: Ch6.(Pg 136) !isset And =='yes'

Recommended Posts

Hello Larry and other forum users,

 

I have trouble understanding the code on page 136:

 

if (!isset($_POST['terms']) AND ($_POST['terms']=='Yes')) {

    print '<p class="error">You must agree to the terms.</p>';
    $okay=FALSE;

}

 

Question(s):

1. Why do I need to include ($_POST['terms'] =='Yes' ?

 

2. If i only include this code in the document:

if ($_POST['terms'] !='Yes') { etc.

}

then i get the error message in my Mozilla browser:

 

Notice: Undefined index: terms in C:\xampp\htdocs\handle_reg.php on line 76

 

The code in red still prints out, but this strange error message appears above it.

 

3. For further testing, if i include only the code:

if ($_POST['terms'] == 'Yes') {
    print '<p class="error">You must agree to the terms.</p>';
    $okay=FALSE;

}

 

and after I check the "agree to terms" box(in the register.html document) then the "You must agree to terms" statement in red appears as expected.

 

But, the undefined index/error message does not appear.

 

*So, I'm confused why there is an undefined index error message and what it means in question #2.*

 

4. Lastly, if I type in the entire code block as shown on page 136:

if (!isset($_POST['terms']) AND ($_POST['terms']=='Yes')) {

    print '<p class="error">You must agree to the terms.</p>';
    $okay=FALSE;

}

The same undefined error index message appears. I'm not sure what's wrong.

 

 

Please help and thank you in advance.

Share this post


Link to post
Share on other sites

I'm still having difficulty understanding this.

 

On pg 136, the text says that the statement: if (!isset($_POST['terms'])) {

 

could be written more exact by changing it to:

 

if (!isset($_POST['terms']) AND ($_POST['terms']=='Yes')) {

 

Question:

Is the bolded segment a typo?

 

Instead, should the statement be written as:

 

if (!isset($_POST['terms']) AND ($_POST['terms'] !='Yes')  {   error message....

 

That way, if the person filling the form does not check the box, both these conditions become TRUE in order to trigger the error message?

 

Your help is appreciated. Thanks in advance.

Share this post


Link to post
Share on other sites

You are correct that it's a typo. It should be 

if (!isset($_POST['terms']) OR ($_POST['terms']!='Yes')) {
I thought this was in the errata, but I'll add it if not. My apologies for the confusion. Note, though, that it should be OR, not AND, because we're saying it's a problem if either condition is true.

Share this post


Link to post
Share on other sites

Sorry, Larry it was my mistake. I should have checked the errata before posting.

 

I've been so captivated to learn from your book that I had not considered the errata! :)

 

Thanks, I understand now.

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...