According to the documentation:
For SELECT, SHOW, DESCRIBE, EXPLAIN and other statements returning resultset, mysql_query() returns a resource on success, or FALSE on error.
For other type of SQL statements, INSERT, UPDATE, DELETE, DROP, etc, mysql_query() returns TRUE on success or FALSE on error.
mysql_query() will also fail and return FALSE if the user does not have permission to access the table(s) referenced by the query.
The mysql_fetch_array() function expects a result resource returned by mysql_query. If that call failed, it returns false and that is what you are passing to your mysql_fetch_array() function, hence why it fails.
The problem is actually in your SQL. You need to have the LIMIT clause last in your queries as such:
SELECT * FROM main WHERE month='$month' AND year='$year' ORDER BY id DESC LIMIT 12
One way to ensure errors in your query don't bleed down into other code is to check the value first:
$q = mysql_query("SELECT * FROM main WHERE month='$month' AND year='$year' ORDER BY id DESC LIMIT 12");
if($q != FALSE)
{
// Query didn't fail, so get results
while ($result = mysql_fetch_array($q))
{
// Do something with $result
}
}