This might not get you all the way there, but it'll help.
Do more error checking. Your first prepare() is unchecked. And when you find that $DBI::errstr holds a value, print it!. Dropping clues on the ground isn't going to do you any good.
Comment on Re: DBI:Problem in binding VARCHAR values to statement