Yeah, whitespaces could mess things up. Whenever I put something into the database and I know it's not supposed to have a space in the beginning or at the end (like dates, IP addresses, etc...) I use PHP's trim() function (
http://www.php.net/manual/en/function.trim.php) to remove whitespace(s) from the beginning and the end of the string. This saves my butt all the time.