用户注册页reg.php
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>注册</title>
</head>
<body>
<div class="content" align="center">
<!--头部-->
<div class="header">
<h1>注册页面</h1>
</div>
<!--中部-->
<div class="middle">
<form action="registeraction.php" method="post">
<table border="0">
<tr>
<td>用户名:</td>
<td><input type="text" id="id_name" name="username" required></td>
</tr>
<tr>
<td>密 码:</td>
<td><input type="password" id="password" name="password" required></td>
</tr>
<tr>
<td>重复密码:</td>
<td><input type="password" id="re_password" name="re_password" required></td>
</tr>
<tr>
<td>姓名:</td>
<td><input type="text" id="name" name="name" required></td>
</tr>
<tr>
<td>电话:</td>
<td><input type="text" id="phone" name="phone" required></td>
</tr>
<tr>
<td colspan="2" align="center" style="color:red;font-size:16px;">
<!--提示信息-->
<?php
$err=isset($_GET["err"])?$_GET["err"]:"";
switch($err) {
case 1:
echo "用户名已存在!";
break;
case 2:
echo "密码与重复密码不一致!";
break;
case 3:
echo '注册成功!<a href="login.php">登陆</a>';
break;
}
?>
</td>
</tr>
<tr>
<td colspan="2" align="center">
<input type="submit" id="register" name="register" value="注册">
<input type="reset" id="reset" name="reset" value="重置">
</td>
</tr>
<tr>
<td colspan="2" align="center">
如果已有账号,快去<a href="login.php">登录</a>吧!
</td>
</tr>
</table>
</form>
</div>
<!--脚部-->
<div class="footer"></div>
</div>
</body>
</html>
注册验证页面registeraction.php
<?php require_once('comm.php');
$username = isset($_POST['username'])?$_POST['username']:"";
$password = isset($_POST['password'])?md5($_POST['password']):"";
$re_password = isset($_POST['re_password'])?md5($_POST['re_password']):"";
$name = isset($_POST['name'])?$_POST['name']:"";
$phone = isset($_POST['phone'])?$_POST['phone']:"";
date_default_timezone_set('PRC');
$time = date('Y-m-d H:i:s');
if($password == $re_password) {
//准备SQL语句,查询用户名
mysql_query("set names 'utf8'");
mysql_select_db($database_wtcl_comm);
$sql_select="SELECT * FROM wtcl_yh WHERE yh_ming='$username'";
//执行SQL语句
$ret = mysql_query($sql_select);
$row = mysql_fetch_array($ret);
//判断用户名是否已存在
if($username == $row['yh_ming']) {
//用户名已存在,显示提示信息
header("Location:reg.php?err=1");
} else {
//用户名不存在,插入数据
//准备SQL语句
$sql_insert = "INSERT INTO wtcl_yh(yh_ming,yh_mi,yh_mingzi,yh_phone,yh_time) VALUES('$username','$password','$name','$phone','$time')";
//执行SQL语句
mysql_query($sql_insert);
header("Location:reg.php?err=3");
}
//关闭数据库
mysql_close();
} else {
header("Location:reg.php?err=2");
}
?>