PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
<?php
$year = date("Y");
$month = date("n");
$day = date("j");
if ($month < "8" and $day < "10") {
$age = $year - 1988;
} else {
$age = $year - 1987;
}
?>
<p><b>How old are you?</b><br>I am <?php echo $age; ?> years old</p>
The problem is that it keeps outputting "17", which is incorrect. From playing around with it I found that it skips the "if" and goes straight for the catch-all "else" condition, hence why I believe the problem lies in the conditions of the "if" statement. But I just can't seem to find what's wrong with it! Any ideas?
I'm just trying to teach myself PHP for the past week or so to give me something else to get my teeth into in the summer holidays, so I'd really appreciate the help.
breaking it apart we get:
$month < "8", returns true.
$day < "10", returns false. At least for the past several days or so.
Both conditions have to be true because you are using 'and'.
johnperkins21: I'll be trying that tonight! Cheers!
Unipus: I think I did get rid of the quotes there once when I was experimenting, and it didn't seem to do any different. I'll look out for that in future though, so thanks for pointing that out