This is a registration program. when the user enters the user name, it will automatically go to the database to check whether the user's user name to be registered has been registered. if it is returned, a prompt is displayed; otherwise, the user can be registered.
This is a registration program. when the user enters the user name, it will automatically go to the database to check whether the user's user name to be registered has been registered. if it is returned, a prompt is displayed; otherwise, the user can be registered.
Conn. php file
-
-
- Var xmlhttp
- Function showhint (str)
- {
- If (str. length = 0)
- {
- Document. getelementbyid ("txthint"). innerhtml = ""
- Return
- }
- Xmlhttp = getxmlhttpobject ()
- If (xmlhttp = null)
- {
- Alert ("browser does not support http request ")
- Return
- }
- Xmlhttp. onreadystatechange = statechanged
- Var geturl = "conn. php? Q = "+ str
- // Sid is to add a random number to prevent the cache technology from being enabled on the page ·
- Geturl = geturl + "& sid =" + math. random ()
- Geturl = encodeuri (geturl );
- Geturl = encodeuri (geturl );
- Xmlhttp. open ("get", geturl, true)
- Xmlhttp. send (null)
- }
- Function statechanged ()
- {
- If (xmlhttp. readystate = 4 | xmlhttp. readystate = "complete ")
- {
- Document. getelementbyid ("txthint"). innerhtml = xmlhttp. responsetext
- }
- }
- Function getxmlhttpobject ()
- {
- Var xmlhttp = null;
- Try
- {
- // Firefox, opera 8.0 +, safari
- Xmlhttp = new xmlhttprequest ();
- }
- Catch (e)
- {
- // Internet explorer
- Try
- {
- Xmlhttp = new activexobject ("msxml2.xmlhttp ");
- }
- Catch (e)
- {
- Xmlhttp = new activexobject ("microsoft. xmlhttp ");
- }
- }
- Return xmlhttp;
- }
- Script
-
-
-
-
-
-
- $ Q = $ _ get ["q"];
- $ Q = urldecode ($ q );
- If (strlen ($ q)> 0)
- {
- $ Conn = @ mysql_connect ("localhost", "root", "1010") or die ("mysql connection error ");
- Mysql_select_db ("xin", $ conn );
- Mysql_query ("set names 'utf8 '");
- $ SQL = "select username from message where username = '$ Q '";
- $ Query = mysql_query ($ SQL );
- @ $ Row = mysql_fetch_array ($ query );
- If (! Emptyempty ($ row ['username'])
- {
- $ Response = "registered! ";
- } Else
- {
- $ Response = "Congratulations! Yes! ";
- }
- Echo $ response;
- }
- ?>
Database
- Drop database if exists 'sin ';
- Create database 'sin '/*! 40100 default character set utf8 */;
- Use 'sin ';
-
- Create table 'message '(
- 'Id' int (11) not null auto_increment,
- 'Username' varchar (20) default null,
- Primary key ('id ')
- ) Engine = innodb auto_increment = 2 default charset = utf8;