The code is as follows |
Copy Code |
$conn =mysql_connect (' localhost ', ' root ', ' root ') or Die (' Database connection error '); mysql_select_db (' demo ', $conn); mysql_query ("Set names ' GBK '"); Detect if a member name exists if ($_post[username]) { $sql = "SELECT * from Users where username= ' $_post[username] '"; $res =mysql_query ($sql) or Die ("Query failed!") "); $US =$_get[name]; echo $US. " 222222 "; $ps tutorial = MD5 ($_post[password]); $sex =$_post[' sex ']; $age =$_post[' age ']; $QQ =$_post[' QQ ']; $phone =$_post[' phone ']; $email =$_post[' email ']; $address =$_post[' address ']; if (Is_array (Mysql_fetch_row ($res)) { echo "This member name already exists! "; }else{ $sql = "INSERT into users (username,password,sex,age,qq,phone,email,address) VALUES (' $US ', ' $ps ', $sex, $age, $QQ, ' $ Phone ', ' $email ', ' $address '); Echo $sql; mysql_query ($sql) or Die ("registration failed"); echo "<script>alert" (' registered success '); location.href= ' login.php ' </script> '; } } ?> <script language= "Web Effects" type= "Text/javascript" > function Docheck () { var username = Document.regform.username.value; var pwd =document.regform.password.value; var Repwd=document.regform.repassword.value; if (username== "") { Alert ("Please enter a username!") "); return false; } if (pwd== "") { Alert ("Please enter a password!") "); return false; } if (repwd!= pwd) { Alert ("Two fill passwords are not the same!") "); return false; } } </script> <script language= "JavaScript" > function Createxmlhttprequest () { var xmlhttp; if (window.activexobject) { XMLHTTP = new ActiveXObject ("Microsoft.XMLHTTP"); }else{ XMLHTTP = new XMLHttpRequest (); } return XMLHTTP; } function CheckName () { var name = document.getElementById (' username '); Get User Name text box var span = document.getElementById (' Name_info '); Gets the span marker used to display the result if (name.value.length <= 4) { Span.style.color = ' #ff0000 '; Set the font color in the span tag to red span.innerhtml = ' username length cannot be less than 4 characters! '; Span tag Content return false; } var xmlhttp = createxmlhttprequest ();//Create Asynchronous Request object var time = new Date (). gettime (); var url = ' regval.php?name= ' + name.value + ' &tmp= ' + time;//constructs the request address Xmlhttp.open ("Get", url,true); Establish an asynchronous request Here we use the Get method to request Xmlhttp.onreadystatechange = function () {//Monitor request status Span.style.color = ' #ff9900 '; span.innerhtml = ' query, please wait! '; if (xmlhttp.readystate = = 4 && xmlhttp.status = 200) { Alert (xmlhttp.responsetext+ "..."); if (Xmlhttp.responsetext.indexof (' no ')!=-1) {//If there is no in the information returned by the server Span.style.color = ' #cb2121 '; Set span marker color to red span.innerhtml = ' username [' + Name.value + '] has been used by other users! '; Document.regform.username.value= ""; }else{//If there is no in the return message Span.style.color = ' #00a800 ';//Set Color to Green span.innerhtml = ' Congratulations, the username is not registered! ' } return true; Delete xmlhttp; Delete Request Object } } xmlhttp.send (null);//Send Request } </script> <form action= "regval.php" method= "POST" Onsubmit= "return Docheck ()" Name= "RegForm" member name: <input type= "text" name= "username" value= "" id= "username" onblur= "checkname ()"/> <span id= "Name_info" ></SPAN> <br> Secret code: <input type= "password" name= "password" "value=" " ><br> Confirm password: <input type= "password" name= "Repassword" value= ""/><BR> Gender: Male: <input name= "Sex" type= "Radio" value= "0" checked= "checked"/> Female: <input name= "Sex" type= "Radio" value= "1"/><br> Ages: <input type= "text" name= "Age" value= "/><br> Qq:<input type= "text" name= "QQ" "value=" "/><br> Tel: <input type= "text" name= "Phone" value= ""/><br> Email:<input type= "text" name= "email" value= "/><br> Add: <input type= "text" name= "Address" value= ""/><br> <input type= "Submit" Name= "sub" value= "Registered"/> <input type= "reset" name= "Re" value= "Cancel"/> </form> |
?
/*
Drop table if exists ' users ';
CREATE table ' users ' (
' id ' int (a) NOT NULL auto_increment,
' username ' varchar (%) not null, ' password ' varchar NOT NULL,
' sex ' int (1) is not null default ' 0 ',
' age ' int (a) NOT NULL ,
' QQ ' int () default NULL,
' phone ' varchar default NULL,
' email ' varchar defaul T null,
' address ' varchar (m) default NULL,
PRIMARY key (' ID ')
) Engine=innodb auto_increment=4 Default CHARSET=GBK;
-- ----------------------------
--Records of users
-- ----------------------------
Insert INTO ' users ' values (' 1 ', ' admin ', ' 21232f297a57a5a743894a0e4a801fc3 ', ' 0 ', ' 22 ', ' 379559090 ', ' 666666 ', ' 666666@1 63.com ', ' Wuhan ');
Insert INTO ' users ' values (' 2 ', ' root ', ' 63a9f0ea7bb98050796b649e85481845 ', ' 0 ', ' 20 ', ' 1244249796 ', ' 8888888 ', ' 8888888 ') @163.com ', ' China ');
Insert INTO ' users ' values (' 3 ', ' www.111cn.net ', ' 96e79218965eb72c92a549dd5a330112 ', ' 0 ', ' 20 ', ' 1244249796 ', ' 8888888 ') , ' 8888888@163.com ', ' China ');
This tutorial downloads the address
Http://down.111cn.net/down/code/php/xinwenxitong/2010/0812/20183.html