Ok now - trying again. Doing each thing separately. Also discovered I had the variable $color to pick up the value of $year - another careless mistake. Changed that.
Went back and made the year validation do just the first part - make sure it was numeric and 4 digits. That worked.
So then, I did, as a separate thing, not nested, a validation of the year to make sure it was before 2008, and with the cute quip about coming from the future.
And that worked!
So why did they not work when nested? Obviously because I did something wrong in the nesting part. Trying it again.
Put in the very first line:
as so: if ( is_numeric ($year) AND strlen ($year) == 4){
This time I left the ending curly brace and just moved it down the page so It would be there.
Then added back in the second part:
as so: if ( is_numeric ($year) AND strlen ($year) == 4){
if ($year >= 2008) {
print "<p>Either you entered your birth year wrong or
you've come from the future!</p>";
} else {
$birthYear = $year;
}
else {
print ' Please enter the year you were born as a four digit number! ';
}
}
Ok….so far so good. Now I need another “else” for the end of the very first conditional. Putting it right after the last curly brace under $year.
Saved it -
and - blank page. What am I missing here?
Ok…for now - I’m just not going to nest things.
Obviously I’m missing something, but I have no clue what - and the book is no help - it is assuming that the code as written works - but not for me.
Revised my page as so:
//validating the year things
if ( is_numeric ($year) AND strlen ($year) == 4){
$birthYear = $year;
}else {
print '<p>Please enter the year you were born as a four
digit number!</p>';
}
and then:
// trying the second part separate - birth year before 2008
if ($year >= 2008) {
print "<p>Either you entered your birth year wrong or you've come
from the future!</p>";
}
And this works! It’s a mystery to me - but at this point, it’s just easier to do things separately than to nest them - for me!
And that’s my second 15 for today!
Check it out - and try not picking a color and see what it says….a bit of fun for me after this frustrating day!
Recent Comments
No comments yet.
Please login to comment.
