Welcome to PHPBuilder! When posting PHP code, please use the board's [noparse]
..
[/noparse] bbcode tags as they make your code much easier to read and analyze.
As for your problem, you need to figure out why the SQL query is failing. You should be checking the return value of [man]mysql_query/man, and if it is boolean false, then you should be using the error message returned by MySQL (e.g. via [man]mysql_error/man) to aid in debugging the failing query.
Also note that you could probably make your code a lot simpler and more efficient by replacing all three queries with a single 'INSERT INTO .. ON DUPLICATE KEY UPDATE' query instead (assuming, of course, that you've properly designed your table with a primary key; if you only want one row per date then your 'id' column is superfluous and should be removed).