-
Notifications
You must be signed in to change notification settings - Fork 0
/
registration.php
271 lines (198 loc) · 7.07 KB
/
registration.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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
<?php
$title= 'registration';
include "connection.php";
include "navbar.php";
function validateUserData($value) {
//remove space
$value = trim($value);
//remove back slash from string
$value = stripslashes($value);
//encode special character
$value = htmlspecialchars($value);
//escape special character before inserting into database table
//return value
return $value;
}
?>
<?php
if(isset($_POST['submit']))
{
$err = [];
if (isset($_POST['id']) && !empty($_POST['id'])) {
$id = validateUserData($_POST['id']);
} else {
$err['id'] = 'Enter id ';
}
if (isset($_POST['first']) && !empty($_POST['first'])) {
$first = validateUserData($_POST['first']);
} else {
$err['first'] = 'Enter first name';
}
if (isset($_POST['last']) && !empty($_POST['last'])) {
$last = validateUserData($_POST['last']);
} else {
$err['last'] = 'Enter last name';
}
//form validation for username
if (isset($_POST['username']) && !empty($_POST['username']) &&
trim($_POST['username']) != '') {
//get username and trim username : remove white space from start and end
$username = validateUserData($_POST['username']);
//check lenght of string
if (strlen($username) >= 8) {
} else {
$err['username'] = 'Username must be minimum 8 character';
}
} else {
$err['username'] = 'Enter Username';
}
if (isset($_POST['password']) && !empty($_POST['password']) &&
trim($_POST['password']) != '') {
//get username and trim username : remove white space from start and end
$password = validateUserData($_POST['password']);
//check lenght of string
if (strlen($password) >= 8) {
} else {
$err['password'] = 'username must be minimum 8 character';
}
} else {
$err['password'] = 'Enter username';
}
if (isset($_POST['email']) && !empty($_POST['email'])) {
$email = validateUserData($_POST['email']);
if (!filter_var($email,FILTER_VALIDATE_EMAIL)) {
$err['email'] = 'Enter Valid Email';
}
} else {
$err['email'] = 'Enter Email';
}
if (isset($_POST['phone']) && !empty($_POST['phone']) && is_numeric($_POST['phone'])) {
$phone = $_POST['phone'];
if (strlen($phone) < 10 ) {
$err['phone'] = 'Enter phone minimum 10 digit';
}
} else {
$err['phone'] = 'Enter phone';
}
if (isset($_FILES['photo']['error']) && $_FILES['photo']['error'] == 0) {
//file size validation
if ($_FILES['photo']['size'] < 1048576) {
$types = ['image/jpeg','image/gif','image/png','image/jpg'];
$image_name = uniqid() . '_' . $_FILES['photo']['name'];
if (in_array($_FILES['photo']['type'], $types)) {
//move file to your folder
if(move_uploaded_file($_FILES['photo']['tmp_name'],
'images/' . $image_name)){
}else {
$err['photo'] = 'File Upload Failed!!';
}
} else {
$err['photo'] = 'File type not allowed';
}
} else {
$err['photo'] = 'File size exceed, 1 MB allowed';
}
}else {
$err['photo'] = 'File Upload Error';
}
if (count($err) == 0) {
$sql= "insert into admin (first,last,username,password,email,contact,pic)values('$first','$last','$username','$password','$email','$phone','$image_name')";
$db->query($sql);
if ($db->affected_rows == 1) ?>
<script type="text/javascript">
alert("Registration successful");
</script>
<?php
}
else
{
?>
<script type="text/javascript">
alert("registration failed.");
</script>
<?php
}
}
?>
<!DOCTYPE html>
<html>
<head>
<title>admin Registration</title>
<link rel="stylesheet" type="text/css" href="style.css">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<style type="text/css">
section
{
margin-top: -20px;
}
</style>
</head>
<body>
<section>
<div class="reg_img">
<div class="box2">
<h1 style="text-align: center; font-size: 35px;font-family: Lucida Console;">       Library Management System</h1>
<h1 style="text-align: center; font-size: 25px;">Admin Registration Form</h1>
<form action="<?php echo $_SERVER['PHP_SELF'] ?>"
method="post" enctype="multipart/form-data">
<div class="login">
<input class="form-control" type="text" name="id" placeholder="enter id"> <br>
<?php
if (isset($err['id'])) {
echo $err['id'];
}
?>
<input class="form-control" type="text" name="first" placeholder="First Name"> <br>
<?php
if (isset($err['first'])) {
echo $err['first'];
}
?>
<input class="form-control" type="text" name="last" placeholder="Last Name"> <br>
<?php
if (isset($err['last'])) {
echo $err['last'];
}
?>
<input class="form-control" type="text" name="username" placeholder="Username"> <br>
<?php
if (isset($err['username'])) {
echo $err['username'];
}
?>
<input class="form-control" type="password" name="password" placeholder="Password"> <br>
<?php
if (isset($err['password'])) {
echo $err['password'];
}
?>
<input class="form-control" type="text" name="email" placeholder="Email" ><br>
<?php
if (isset($err['email'])) {
echo $err['email'];
}
?>
<input class="form-control" type="text" name="phone" placeholder="Phone No"><br>
<?php
if (isset($err['phone'])) {
echo $err['phone'];
}
?>
<input class="btn btn-default" style="display:block;width: 100%;height: 34px;"value="upload image" onclick="document.getElementById('image').click()"></input>
<input type="file" style="display:none;" name="photo" class="form-control" id="image" placeholder="Enter image" >
<?php
if (isset($err['photo'])) {
echo $err['photo'];
}
?><br>
<input class="btn btn-danger" style="display:block;width: 100%;height: 34px;" type="submit" name="submit" value="Sign Up" style="color: black; width: 70px; height: 30px"> </div>
</form>
</div>
</div>
</section>
</body>
</html>