View Single Post
Old 03-01-2013, 11:17 PM   PM User | #2
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,662
Thanks: 4
Thanked 2,452 Times in 2,421 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
The problem looks to me that its not actually caused by the daysInMonth+1 as being a requirement, rather that daysInMonth is incorrect. Of course the daysInMonth + 1 would be invalid for something like april 31, which will check out as fine here. So you should just be checking for <= daysInMonth as you have assumed and that's correct.

Here's the problem:
Code:
		if (month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12);
		daysInMonth = 31;
		
		if (month == 4 || month ==6 || month == 9 || month == 11);
		daysInMonth = 30;
With the exception of february since it overwrites (although will still assign here as well), EVERY month is assigned daysInMonth = 30. That's caused by this:
Code:
if (month == 4 || month ==6 || month == 9 || month == 11);
                                                         ^
A semi-colon at the end of any control structure such as an if or a loop is true once and only once (and for the last option if its an iteration). So no matter what the month, even a month of -1, the daysInMonth will be 30 here, and the only exception is the 2nd month which then overwrites.

I'd recommend the use of braced evaluations as well as using elseif (since it can only be one of these possible options) or a switch.
__________________
As of PHP 5.5, the MySQL library has been officially deprecated. It is recommended to move to either MySQLi or PDO libraries for your mysql connectivity. See here for help choosing which interface you prefer: http://php.net/manual/en/mysqlinfo.api.choosing.php
Fou-Lu is offline   Reply With Quote