注册页面及验证

来源:互联网 发布:用数据做事更准确 编辑:程序博客网 时间:2024/05/22 07:55
<table align="center"  bgcolor="#CCCCCC" >
<form action="reg.php" method="post" onsubmit="return check_form()">
<tr><td>  
用户名:</td><td><input type="text " name="username">  只能输入英文、数字、空格
</td></tr><tr><td>
口令: </td><td> <input type="password" name="password1" >
</td></tr><tr><td>
确认口令 :</td><td> <input type="password" name="password2" >
</td></tr><tr><td>
性别 :</td><td><input type="radio" name="sex">男 <input type="radio"  name="sex">女
</td></tr><tr><td>
邮箱 :</td><td> <input type="text" name="mail">
</td></tr><tr><td>
照片 : </td><td><input type="text" name="photo" >
</td></tr><tr><td>
电话 :</td><td> <input type="text" name="tel">
</td></tr><tr><td>
生日 :</td><td> <input type="text" name="birthday" >
</td></tr><tr><td>
爱好 :</td><td> <input type="text" name="like" >
</td></tr><tr><td>
自我爱好 :</td><td> <input type="text" name="introduce" >
</td></tr><tr><td>
 </td><td><input type="submit" name="ok" value="register new user" onclick="return check_from()">
</form>
</td></td>
</table>

<script language="javascript">
function check_from(){
//getElementByName
var username=document.geteElementByName('username').value;
var password1=document.geteElementByName('password1').value;
var password2=document.geteElementByName('password2').value;
var sex=document.geteElementByName('sex').value;
var mail=document.geteElementByName('mail').value;
var photo=document.geteElementByName('photo').value;
var tel=document.geteElementByName('tel').value;
var birthday=document.geteElementByName('birthday').value;
var like=document.geteElementByName('like').value;
var introduce=document.geteElementByName('introduce').value;



pattern=/^[a-zA-Z0-9-]+@[a-zA-Z0-9_-]+(.[a-zA-Z0-9_-]+)/;
if(pattern.test(username)){
alert ("error");
}else{
     if(password1==password2){

<?php

//获取表单信息写入数据表
@include(dbconnect.php);
@$username=$_POST["username"];
@$password=$_POST["password"];
@$sex=$_POST["sex"];
@$mail=$_POST["mail"];
@$photo=$_POST["photo"];
@$tel=$_POST["tel"];
@$birthday=$_POST["birthday"];
@$like=$_POST["like"];

@$sql="insert into tbl_user  set id='',username='$username',password='$password',sex='$sex',mail='$mail',tel='$tel',birthday='$birthday',like='$like'";
@mysql_query($sql);
//生成表单来接受用户信息
?>



    }

 }
 
 
}

</script>