好得很程序员自学网

<tfoot draggable='sEl'></tfoot>

php 用户注册页面代码 - 综合实例

php 用户注册页面代码

php 用户注册页面代码 这款用户注册程序是一款包括有数据库,注册页面,注册js 验证是一款完整理的php+mysql实用的用户注册代码。

*/  $conn =mysql_connect( 'localhost' , 'root' , 'root' ) or   die ( '数据库连接错误' );  mysql_select_db( 'demo' , $conn );  mysql_query( "set names 'gbk'" );  //检测会员名称是否存在   if ( $_post [username]){     $sql = "select * from users where username='$_post[username]'" ;     $res =mysql_query( $sql ) or   die ( "查询失败!" );     $us = $_get [name];     echo   $us . "222222" ;     $ps = 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   "该会员名已经存在!" ;    } 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 ( "注册失败" );          echo   "<script>alert('注册成功');location.href='login.php'</script>" ;    }  }  ?>  <script language= ""  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( "请输入用户名!" );       return  false;  }  if (pwd== "" ){    alert( "请输入密码!" );       return  false;  }  if (repwd != pwd){    alert( "两次填写的密码不相同!" );     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' );  //获取用户名文本框     var  span = document.getelementbyid( 'name_info' );  //获取用于显示结果的span标记     if (name.value.length <= 4){    span.style.color =  '#ff0000' ;  //设置span标记内的字体颜色为红色     span.innerhtml =  '用户名长度不能少于4个字符!' ;  //span标记内容      return  false;   }    var  xmlhttp = createxmlhttprequest(); //创建异步请求对象     var  time =  new   date ().gettime();    var  url =  'regval.php?name='  + name.value +  '&tmp='  + time; //构造出请求地址    xmlhttp.open( "get" ,url,true);  //建立一个异步请求     //这里我们使用get方式请求    xmlhttp.onreadystatechange =  function (){  //监视请求状态     span.style.color =  '#ff9900' ;    span.innerhtml =  '查询中,请稍候!' ;     if (xmlhttp.readystate == 4 && xmlhttp.status == 200){  alert(xmlhttp.responsetext+ "........" );      if (xmlhttp.responsetext.indexof( 'no' ) != -1){  //如果服务器返回的信息中有no       span.style.color =  '#cb2121' ;  //设置span标记颜色为红色       span.innerhtml =  '用户名['  + name.value +  ']已经被别的用户使用!' ;       //document.regform.username.value="";      } else { //如果返回信息中没有no       span.style.color =  '#00a800' ; //设置颜色为绿色       span.innerhtml =  '恭喜您,该用户名未被注册!' ;     }      return  true;      delete  xmlhttp;  //删除请求对象     }   }   xmlhttp.send(null);  //发送请求   }  </script>    <form action= "regval.php"  method= "post"  onsubmit= "return docheck()"  name= "regform" >    会员名称:    <input type= "text"  name= "username"  value= ""  id= "username"  onblur= "checkname()" />  <span id= "name_info" ></span>    <br>    密&nbsp;&nbsp;&nbsp;&nbsp;码:    <input type= "password"  name= "password"  value= "" /><br>    确认密码:    <input type= "password"  name= "repassword"  value= "" /><br>  性别:  男:<input name= "sex"  type= "radio"  value= "0"  checked= "checked" />  女:<input name= "sex"  type= "radio"  value= "1" /><br>  年龄:<input type= "text"  name= "age"  value= "" /><br>  qq:<input type= "text"  name= "qq"  value= "" /><br>  电话:<input type= "text"  name= "phone"  value= "" /><br>  email:<input type= "text"  name= "email"  value= "" /><br>  地址:<input type= "text"  name= "address"  value= "" /><br>    <input type= "submit"  name= "sub"  value= "注册" />    <input type= "reset"  name= "re"  value= "取消" />    </form>  <?  /*  drop table  if  exists `users`;  create table `users` (    `id` int(10) not null auto_increment,    `username` varchar(50) not null,    `password` varchar(50) not null,    `sex` int(1) not null  default   '0' ,    `age` int(10) not null,    `qq` int(15)  default  null,    `phone` varchar(50)  default  null,    `email` varchar(50)  default  null,    `address` varchar(100)  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@163测试数据' ,  '武汉' );  insert into `users` values ( '2' ,  'root' ,  '63a9f0ea7bb98050796b649e85481845' ,  '0' ,  '20' ,  '1244249796' ,  '8888888' ,  '8888888@163测试数据' ,  '中国' );  insert into `users` values ( '3' ,  'HdhCmsTest111cn.net' ,  '96e79218965eb72c92a549dd5a330112' ,  '0' ,  '20' ,  '1244249796' ,  '8888888' ,  '8888888@163测试数据' ,  '中国' ); 

查看更多关于php 用户注册页面代码 - 综合实例的详细内容...

  阅读:60次