Repository navigation
Expand file tree
/
Copy pathsubmit.php
More file actions
121 lines (99 loc) · 4.35 KB
/
Copy pathsubmit.php
File metadata and controls
121 lines (99 loc) · 4.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<?PHP
header("Content-Type: text/html; charset=utf-8");
if(!isset($_POST["ag"])){
echo '<script language="JavaScript">;alert("必须勾选用户协议");location.href="login.php";</script>;';}
// exit("必须勾选用户协议");}
//检测是否有submit操作
include('connect.php');//链接数据库
$name = $_POST['name'];//post获得用户名表单值
$password = $_POST['password'];//post获得用户密码单值
$idnew = $_POST['id'];
$tel = $_POST['tel'];
$repeat_password = $_POST['repeat_password'];
$school = $_POST['school'];
$txt_hyan = $_POST['txt_hyan'];
$txt_yan = $_POST['txt_yan'];
$vcode = $_POST['vcode'];
//读取手机验证码
$code_sql = "select vcode,date from vcode where tel = '$tel' order by date desc'";
$code_res = $conn->query($code_sql);
$row= $code_res->fetch_array();
$new_vcode = $row['vcode'];
$code_time = $row['date'];
$sql="select * from register where id='$idnew'";
$rs=mysqli_query($conn,$sql);
$arr = mysqli_fetch_array($rs,MYSQL_ASSOC);
echo mysql_error();
if ($name && $password && $idnew && $tel && $repeat_password && $school && $txt_yan && $vcode){
//如果用户名和密码都不为空
if (!($new_vcode==$vcode)){
echo '<script language="JavaScript">;
alert("手机验证码输入错误");
location.href="login.php";</script>;';
} else if(date("Y/m/d G:i:s")-$code_time>1800) {
echo '<script language="JavaScript">;
alert("手机验证码超时");
location.href="login.php";</script>;';
} else if (!($txt_hyan==$txt_yan))
{
echo '<script language="JavaScript">;
alert("验证码输入错误");
location.href="login.php";</script>;';
}else{
if($arr['id']==$idnew)
{
echo '<script language="JavaScript">;alert("用户名已存在,请重新注册!");location.href="login.php";</script>;';
}
// header("Location: login.html");
else
{
if (!($password==$repeat_password))
{
echo '<script language="JavaScript">;
alert("两次输入密码必须相同");
location.href="login.php";</script>;';
}
else {
$q="insert into register (id,name,password,tel,school) values ('$idnew','$name','$password','$tel','$school')";//向数据库插入表单传来的值的sql
$reslut=mysqli_query($conn,$q);//执行sql
if (!$reslut) {
die('Error: ' . mysqli_error());//如果sql执行失败输出错误
}else{
echo '<script language="JavaScript">;alert("注册成功!");location.href="denglu.html";</script>;';
// echo "注册成功";//成功输出注册成功
// header("Location: tiaozhuang.html");//跳转到登陆界面
}
mysqli_close($conn);//关闭数据库
// 面向对象
// if ($conn->query($q) === TRUE) {
// echo "注册成功";
//
// header("Location: tiaozhuang.html");
// } else {
// echo "Error: " . $sql . "<br>" . $conn->error;
// }
//
// $conn->close();
}
}
}
}else{//如果用户名或密码有空
// echo "表单填写不完整";
echo '<script language="JavaScript">;alert("注册信息填写不完整,请重新填写");location.href="login.php";</script>;';
// echo "
// <script>
// setTimeout(function(){window.location.href='login.html';},1000);
// </script>";
//如果错误使用js 1秒后跳转到登录页面重试;
mysql_close($conn);//关闭数据库
}
?>
</body>
</html>