You really should double check your code.
Consider this:
" .... Action=\"$SERVER[PHP_SELF]\" ...."
will not work, it will treat it as a string, not a variable and also, enclose your indexes with single/double qoutes,
eg: " .... Action='" . $SERVER['PHP_SELF'] . " ....."
I've seen this error a lot in your codes.
Also the variable $Msg is not the same as $msg, PHP is case sensitive (guess you came from a different programming language...)
If your PHP settings is set to display all errors, you'd be getting a lot of warnings and errors. Initialize variables first before using them.
My advice, read on the basics first before trying something like this (no pun or insult intended).
c ya!