My suggestion would be put some checking around your sprintf, and make sure all the values you used to form your sql statement are not undef and well-formated. Most likely it is something like this. Even if not as simple as my professional guess, my suggestion would still be a good style you want take into consideration.