Jump to content
Larry Ullman's Book Forums

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.

Link to comment
Share on other sites

  • 2 weeks later...

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.

Link to comment
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.
Link to comment
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.

Link to comment
Share on other sites

 Share

×
×
  • Create New...