It could have been related to that space in between '(6536,' and '$userid)' ; (6536, $userid).
or any other invisible character that got caught up in the script ( if you copy-pasted it). I've wasted days on scripts only to find out they were always good, just had unknown, invisible characters (usually when I copy-paste stuff).
This program;
Perl Editor by EngInSite
is for windows (although i can run it with Wine too), is free and has an option to show all hidden characters in the script.