in reply to MySQL Problem

use strict would help and the error msg would probably help some too!

Why mix bound params and within string variables? Make them all bound in case your $user or $AP vars have quotes in them which needed to be escaped.

@hours[$hour] should be $hours[$hour].

There may be more but it would be much easier if we had the error message which usually gives some hints.