-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathupdate.php
152 lines (119 loc) · 3.86 KB
/
update.php
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
<!DOCTYPE html>
<html lang="zh-cn">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>更新信息表单处理</title>
<link href="css/bootstrap.min.css" rel="stylesheet">
<link href="img/logo.ico" rel="shortcut icon" />
<link rel="stylesheet" type="text/css" href="css/sweetalert.css"/>
<script src="js/sweetalert.js" type="text/javascript" charset="utf-8"></script>
</head>
<body>
<?php
require 'common.php';
$action=isset($_GET['action'])?$_GET['action']:'';
if($action=='info'){
$sex=_POST('sex');
$motto=_POST('motto');
$email=_POST('email');
$telenumber=_POST('telenumber');
$username=$_COOKIE["username"];
$sql="UPDATE
userinformation
SET
sex='$sex',
motto='$motto',
email='$email',
phonenumber='$telenumber'
WHERE
username = '$username'
";
query("$sql");
mysqli_close($mydb);
echo "<script>self.location='userHomepage.php'; </script>";
}
if($action=='img'){
$username=$_COOKIE["username"];
if ((($_FILES["file"]["type"] == "image/gif")
|| ($_FILES["file"]["type"] == "image/jpeg")
|| ($_FILES["file"]["type"] == "image/png")
|| ($_FILES["file"]["type"] == "image/pjpeg"))
&& ($_FILES["file"]["size"] < 2097152))
{
if ($_FILES["file"]["error"] > 0)
{
echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
}
else
{
/*echo "Upload: " . $_FILES["file"]["name"] . "<br />";
echo "Type: " . $_FILES["file"]["type"] . "<br />";
echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />";*/
//改变文件名字
function name(){
global $filename;
static $no=0;
$no++;
if($_FILES["file"]["type"] == "image/gif")
{
$filename=$no.'.gif';
}
if($_FILES["file"]["type"] == "image/jpeg")
{
$filename=$no.'.jpeg';
}if($_FILES["file"]["type"] == "image/png")
{
$filename=$no.'.png';
}if($_FILES["file"]["type"] == "image/pjpeg")
{
$filename=$no.'.pjpeg';
}
}
do{name();}
while(file_exists("userimg/" . $filename));
//存入服务器文件夹
move_uploaded_file($_FILES["file"]["tmp_name"],
"userimg/" . $filename);
echo "Stored in: " . "userimg/" . $filename;
//存入数据库
$filename="url("."userimg/".$filename.")";
$sql="update userinformation set userimg = '$filename' where username = '$username'";
query($sql);
}
}
else
{
echo "<script>alert('文件类型错误或文件大于2M')</script>";
}
echo "<script>self.location='updatedata.php'</script>";
}
/*修改密码*/
if($action=='changepassword'){
$username=$_COOKIE['username'];
$inputoldpassword=md5(_POST('oldpassword'));
$newpassword=md5(_POST('newpassword'));
/*确认旧密码与用户名是否匹配*/
$sql="select password from userinformation where username='$username'";
$result=fetch_array($sql);
$password=$result['password'];
if($inputoldpassword==$password){
$change="update userinformation set password = '$newpassword' where username = '$username'";
query($change);
setcookie("username");
echo '<script>swal("修改成功,点击转跳至登录页面");</script>';
echo "<script>self.location='BeforeHomepage.php';</script>";
}
else{
echo '<script>swal("密码输入错误");</script>';
echo "<script>self.location='updatedata.php';</script>";
}
}
mysqli_close($mydb);
?>
<script src="http://cdn.bootcss.com/jquery/1.11.1/jquery.min.js"></script>
<script src="js/bootstrap.min.js"></script>
</body>
</html>