function register_user()
{

    global $imageurl, $boardurl, $default_dbname;
    global $userid, $userpassword, $userpasswordverify, $username;
    global $useremail, $userprofile, $usercomment;
    global $user_tablename, $maileron;


    if ($username =="") { error_message('FIELD_MISSING', 
                          Name", "F-1"); }
    if ($userid =="") { error_message('FIELD_MISSING', 
                       "User ID", "U-1"); }
    if (ereg(" ", $userid)) { error_message('NO_SPACE', 
                             "User ID", "U-2"); }
    if (eregi("[^ a-z0-9], $userid)) 
       { error_message('USERID_INVALID', "User ID", "U-3"); }
    if (ereg(" ", $userpassword)) 
       { error_message('NO_SPACE', "Password", "P-1"); }

    if ($userpassword =="") 
       { error_message('FIELD_MISSING', "Password", "P-2"); }
    if ($userpasswordverify =="") 
       { error_message('FIELD_MISSING', "Retype Password", "P-3"); }
    if ($useremail =="") 
       { error_message('FIELD_MISSING', "Email", "E-1"); }
    if ($userprofile =="") 
       { $userprofile = "I'm too shy to introduce myself:-)"; }

    if(strlen($userid) < 5) 
      { error_message('USERID_SHORT', "User ID", "U-6"); }
    if(strlen($userpassword) < 5) 
      { error_message('PASSWORD_SHORT', "Password", "P-4"); }
    if($userid == $userpassword) 
      { error_message('USERID_PASSWORD_SAME', "Password", "P-5"); }
    if($userpassword != $userpasswordverify) 
      { error_message('PASSWORD_MISMATCH', "Password", "P-6"); }

    if(!(email_check($useremail))) 
      { error_message('USEREMAIL_INVALID', 'Email', "E-2"); }

#
# --  Database Connect.
#

    db_connect($default_dbname);

    if(in_use($userid)) 
      { error_message('USERID_IN_USE', 'User ID', "I-6"); }
#
# --  Insert Data
#


    $groups = "demo_users";
    for($k = 1; $k <= strlen($userpassword); $k++) {
        $passwordchar .= '*';
    }

    $orguserpassword = $userpassword;
    $userpassword = ($userpassword);


    $username = addslashes($username);
    $userprofile = addslashes($userprofile);


    $sqlquery = "'$userid','$username',encrypt('$userpassword','.v'),
                 '$useremail','$groups', '$userprofile'";

    $result = mysql_query("insert into $user_tablename values 
                         ($sqlquery) ");
    if(!$result) {
        error_message('DB_ERROR', '');
    }
}