After smoking a huge blunt, and taking a couple of vicadine, I think I know what the issue is.
IF your variable that you're doing the search on as a tick or a back-tick in the variable, that will end the "string" to search for, but that leaves one open tick left, and then the script bombs.
$variable = addslashes($variable);
before your query and see if that makes the difference.