ambrennan Posted April 1, 2006 Share Posted April 1, 2006 I'm new to php and having trouble writing an If statement (at least I think it should be an if statement)which would check whether the user has entered an invalid date for a month and display an error message like "there are only 28 says in February" or 30 days in April. I have been trying the code below which is not workingif ($arrDate_mon = 2, $arrDate_day <28) { echo "<h2>There are only 28 days in February</h2>" Quote Link to comment Share on other sites More sharing options...
toplay Posted April 1, 2006 Share Posted April 1, 2006 Example:[code]if (2 == $arrDate_mon && $arrDate_day > 28) { echo "<h2>There are only 28 days in February</h2>"}[/code]However, it's best to check the date entered as a whole because the above doesn't account for leap years where you can have 29 days in February. Try using checkdate() function:[a href=\"http://us2.php.net/manual/en/function.checkdate.php\" target=\"_blank\"]http://us2.php.net/manual/en/function.checkdate.php[/a] Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted April 1, 2006 Share Posted April 1, 2006 That is not the correct syntax for an "if" statement. Where did you see that syntax?It should be something like:[code]<?phpif ($arrDate_mon == 2 && $arrDate_day > 28) echo "<h2>There are only 28 days in February</h2>";?>[/code]Of course, this check will not work in leap years.Ken Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.