I used the code exactly as shown above, remember you must pass the name of the tag in all caps, otherwise it isn't equal. Incidently, I didn't return nil on any of my attempts, even when passing a value that is obviously incorrect. I did receive the correct values though ...
I have a block with 2 attributes, NAME and SIZE and I call the routine as such:
(get_attribute (car (entsel)) "NAME")
The return is:
NAMEwidget1
nil
I change the attribute name selecting the same block:
(get_attribute (car (entsel)) "nothing")
NAME1111
SIZE1111
nil
The problem is that you are obviously passing lowercase attribute names and your variables are global .. change the vars to local and pass uppercase attribute names.