in reply to MySQL Problem

As others have said: check the error string ($DBI::errstr) after your prepare and execute statements. Also, consider using the quote method to prepare your SQL query so you don't run into trouble with embedded apostrophes in arguments and other similar nastiness.

Also, do you really want @hours[$hour] or do you mean $hours[$hour]? Is param a function that returns something, or did you intend to use a hash ($param{title}) or a method call ($query->param("title"))?

There are a couple of other debugging techniques that can be helpful in situations like this. One is to concatenate your SQL query into a string and print that to the console/log/whatever, then inspect it to make sure you got the results you were expecting. Another is to connect directly to the database using the command-line SQL monitor and tune your query there to make sure it's doing what you think.