*为必填项用户名:name="username"size="20"class="c3a">*密码:name="password"size="20"class="c3a">*确认密码:id="cpassword">*email:*性别:男女name="sex"value="female"/>保密验证码:type="text"class" />
php简单注册页面代码
注册页面zhuce.html
function Check()// 验证表单数据有效性的函数
{
if (https://www.doczj.com/doc/6216312984.html,ername.value=="")
{
window.alert('请输入用户名!');
return false;
}
if (https://www.doczj.com/doc/6216312984.html,ername.value.length<4)
{
window.alert('用户名长度必须大于4!');
return false;
}
if (document.send.password.value=="")
{
alert('请输入密码!');
return false;
}
if (document.send.password.value.length<6)
{
alert('密码长度必须大于6!');
return false;
}
if (document.send.password.value!=
document.send.cpassword.value)
alert('确认密码与密码不一致!');
return false;
}
if (document.send.email.value=="")
{
alert('请输入Email!');
return false;
}
if(document.send.email.value.indexOf("@")==-1)
{
alert('请输入有效的email地址!'); return false;
}
if (document.send.code.value=="")
{
alert('请输入验证码!');
return false;
}
return true;
}
插入页面insert.php
$conn=mysqli_connect("localhost","root","root","userman"); $conn->query('set names gb2312');
if(empty($conn))
{
die("数据库连接失败");
}
$UserName=$_POST['username'];
$pwd=$_POST['password'];
$email=$_POST['email'];
$sex=$_POST['sex'];
$time=time();
$code=strtolower($_POST["code"]);
$str="select * from users where username='".$username."'";
$result1=$conn->query($str);
$row=$result1->fetch_row();
3 / 5
{
$temp="已有人注册此名,请重新选择名字!";
echo $temp;
echo"返回";
}
else {
if( $_SESSION['sname']==$code)
{
echo $temp="认证码成功";
$sql="INSERT INTO users VALUES('$username',
'$password','$email','$sex','$time')";
$result=$conn->query($sql);
if($result==true)
{
$_SESSION['mail']="注册成功,请登陆";
echo "";
}
else {echo "注册失败".mysql_error();}
}
else {echo "认证码错误";}
}
?>
5 / 5