-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpostReg.php
More file actions
70 lines (69 loc) · 2.12 KB
/
postReg.php
File metadata and controls
70 lines (69 loc) · 2.12 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
<?php
header("Content-type: text/html; charset=utf-8");
$username = trim($_POST['username']);
$usernameReg = "/^[a-zA-Z0-9]{3,10}$/";
if(!preg_match($usernameReg,$username)) {
echo "<script>alert('(来自后端)用户名只能是由大小写字母、数字构成,且长度为3-10!');history.back();</script>";
exit;
}
$pw = trim($_POST['pw']);
$pwReg = "/^[a-zA-Z0-9_\-*]{6,10}$/";
if(!preg_match($pwReg,$pw)) {
echo "<script>alert('(来自后端)密码只能是由大小写字母、数字、下划线、-和*构成,且长度为6-10');history.back();</script>";
exit;
}
$rpw = trim($_POST['rpw']);
if($pw !== $rpw) {
echo "<script>alert('(来自后端)重复密码必须和密码一致!');history.back();</script>";
exit;
}
$email = trim($_POST['email']);
if($email){
$emailReg = "/^[a-zA-Z0-9_\-]+@([a-zA-Z0-9]+\.)+(com|cn|net|org)$/";
if(!preg_match($emailReg,$email)){
echo "<script>alert('(来自后端)邮箱格式不对!');history.back();</script>";
exit;
}
}
$sex = $_POST['sex'];
$fav = $_POST['fav'];
/*if($fav){
$fav = implode(",",$fav);
}
if(!strlen($username)){
echo "<script>alert('用户名必须填写!');history.back();</script>";
exit;
}
if(!strlen($pw)){
echo "<script>alert('密码必须填写!');history.back();</script>";
exit;
}
if($pw !== $rpw){
echo "<script>alert('重复密码必须和密码一致!');history.back();</script>";
exit;
}*/
$pw = md5($pw);
$conn = mysqli_connect("localhost","root","root","member3");
include 'conn.php';
// 判断用户名是否被占用
$sql = "select * from userinfo where username = '$username'";
$result = mysqli_query($conn,$sql);
// 判断$result这个结果集里是否有记录
if(mysqli_num_rows($result)){
echo "此用户名已被占用";
exit;
}
// 第三步
$sql = "insert into userinfo (username, pw, email, sex, fav) values ('$username','$pw','$email','$sex','$fav')";
// 第四步
$result = mysqli_query($conn,$sql);
// 调试
echo $sql . "<br>";
echo mysqli_error($conn);
// 给出反馈
if($result){
echo "Insert Data Successful!";
}
else{
echo "Insert Data Error!";
}