You have another variable on the page using mid... I usually get caught on it when getting a menu ID... which i usualy call mID in the db... so i call it as that on the page and all hell breaks loose...
__________________
Note: I do not test code. I just write it off the top of my head. There might be bugs in it! But if any thing I gave you the overall theory of what you need to accomplish. Also there are plenty of other ways to accomplish this same thing. I just gave one example of it. Other ways might be faster and more efficient.