So first...if you want to know if it will work or not....test it.
So here's my two cents....
1) You don't seem to ever set the var $_SESSION['nam'], so that probably won't work.
2) Your coding assumes register_globals is on. You should learn to code assuming it is off.
3) Seperating the variable from the string is common practice.
eg.
echo "<form action=\"$PHP_SELF\" method=\"post\">\n";
// Should be
echo "<form action=\"".$_SERVER['PHP_SELF']."\" method=\"post\">\n";
//Or
echo "<form action=\"{$_SERVER['PHP_SELF']}\" method=\"post\">\n";
HTH