// [Original] ajax user registration function tutorial 3
This tutorial is original on this site.
Author: www.drise.cn
Email: drise@163.com
QQ: 271728967
//
Now the third step is to write the type. php file, which is used to determine whether the user name exists and then send the data to the user.
<? Php
Header ("Content-type: text/html; charset = gb2312"); // set the document encoding to gb2312 to prevent gibberish.
$ Xm = Strreplace (isset ($ _ GET ['txt '])? $ _ GET ['txt ']: 'null'); // obtain the user name
If (preg_match ("/^ [". chr (0xa1 ). "-". chr (0xff ). "] + $/", $ xm) {// determines whether the first user name is a Chinese character,
Echo ("<div id = 'phperblog _ showinfo_red '> sorry, Chinese cannot be used as the user name! </Div> ");
Exit ();
}
If ($ xm = 'null' | $ xm = ''| strlen ($ xm)> 10 | strlen ($ xm) <3) {// determine the validity of the user name
Echo ("<div id = 'phperblog _ showinfo_red '> sorry, the user name you entered is invalid. The user name consists of 3-10aa_zz and numbers! </Div> ");
Exit ();
} Else {
$ Result = mysql_query ("select uname from tablename where uname = '$ xm'") or die ('error! '. "Error system busy... plase wait! ");
If (! Mysql_num_rows ($ result )){
Echo ("<div id = 'phperblog _ showinfo_reg '> congratulations! User Name ". $ xm." is not yet registered. You can register it! </Div> ");
} Else {
Echo ("<div id = 'phperblog _ showinfo_red '> sorry, please select another name for your registration! </Div> ");
}
}
?>