Thanks Chuck, but I get this error after that edit:
Parse error: syntax error, unexpected T_VARIABLE in /gallery/member.php on line 123
Iniitally I just pasted in the bold code as you said, but got the error, then I just pasted and replaced the whole section with what you have above, but still the same error is produced. So it's not an editing mistake
Any ideas, thanks.