I don't know about the SQL etc, but try changing:
if {$admin_p}{
to
if {$admin_p} {
I believe there should be a space between the close and open brackets.
cheers, Torben