-
Notifications
You must be signed in to change notification settings - Fork 0
/
register.php
248 lines (153 loc) · 6.63 KB
/
register.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
<?php
//THESE ARE IF YOU DO NOT USE A SEPARATE CONFIG FILE FOR PHP LOGINS
//define('DB_SERVER', '');
//define('DB_USERNAME', '');
//define('DB_PASSWORD', '');
//define('DB_NAME', '');
require_once "php/db.php";
$link = mysqli_connect(DB_SERVER, DB_USERNAME, DB_PASSWORD, DB_NAME);
if($link === false){
die("ERROR: Could not connect. " . mysqli_connect_error());
}
$email = $password = $confirm_password = $fn = $ln = "";
$email_err = $password_err = $confirm_password_err = $fn_err = $ln_err = "";
if($_SERVER["REQUEST_METHOD"] == "POST"){
if(empty(trim($_POST["fn"]))){
$fn_err = "Please enter a Firstname";
}
else{
$fn = trim($_POST["fn"]);
}
if(empty(trim($_POST["ln"]))){
$ln_err = "Please enter a Firstname";
}
else{
$ln = trim($_POST["ln"]);
}
if(empty(trim($_POST["email"]))){
$email_err = "Please enter a email.";
}
else{
$sql = "SELECT id FROM users WHERE email = ?";
if($stmt = mysqli_prepare($link, $sql)){
mysqli_stmt_bind_param($stmt, "s", $param_email);
$param_email = trim($_POST["email"]);
if(mysqli_stmt_execute($stmt)){
mysqli_stmt_store_result($stmt);
if(mysqli_stmt_num_rows($stmt) == 1){
$email_err = "This email is already taken.";
} else{
$email = trim($_POST["email"]);
}
} else{
echo "Oops! Something went wrong. Please try again later.";
}
mysqli_stmt_close($stmt);
}
}
if(empty(trim($_POST["password"]))){
$password_err = "Please enter a password.";
}
elseif(strlen(trim($_POST["password"])) < 8){
$password_err = "Password must have at least 8 characters.";
}
else{
$password = trim($_POST["password"]);
}
if(empty(trim($_POST["confirm_password"]))){
$confirm_password_err = "Please confirm password.";
}
else{
$confirm_password = trim($_POST["confirm_password"]);
if(empty($password_err) && ($password != $confirm_password)){
$confirm_password_err = "Password did not match.";
}
}
if(empty($fn_err) && empty($ln_err) && empty($email_err) && empty($password_err) && empty($confirm_password_err)){
$sql = "INSERT INTO users (firstname, lastname, email, password) VALUES (?, ?, ?, ?)";
if($stmt = mysqli_prepare($link, $sql)){
mysqli_stmt_bind_param($stmt, "ssss", $parm_fn, $parm_ln, $param_email, $param_password);
$parm_fn = $fn;
$parm_ln = $ln;
$param_email = $email;
$param_password = password_hash($password, PASSWORD_DEFAULT);
if(mysqli_stmt_execute($stmt)){
header("location: login.php");
}
else{
echo "Something went wrong. 1 Please try again later.";
}
mysqli_stmt_close($stmt);
}
}
mysqli_close($link);
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Sign Up</title>
<link rel="stylesheet" href="css/bootstrap.css">
<link rel="stylesheet" href="css/style.css">
<!-- Cookie Consent by https://www.FreePrivacyPolicy.com -->
<script type="text/javascript" src="js/cookie-consent.js"></script>
<script type="text/javascript">
document.addEventListener('DOMContentLoaded', function () {
cookieconsent.run({"notice_banner_type":"interstitial","consent_type":"express","palette":"dark","language":"en","website_name":"Avicii","change_preferences_selector":"#changePreferences"});
});
</script>
<noscript>Cookie Consent by <a href="https://www.FreePrivacyPolicy.com/free-cookie-consent/" rel="nofollow noopener">FreePrivacyPolicy.com</a></noscript>
<!-- End Cookie Consent -->
<style type="text/css">
body{ font: 14px sans-serif; }
.wrapper{ width: 350px; padding: 20px; background-color: white; color: black; border-radius: 10px}
.help-block{color: red;}
</style>
</head>
<body>
<?php
session_start();
include('php/navbar.php')
?>
<div class="container" id="page-cont">
<div class="wrapper mx-auto">
<h2>Sign Up</h2>
<p>Please fill this form to create an account.</p>
<form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>" method="post">
<div class="form-group <?php echo (!empty($fn_err)) ? 'has-error' : ''; ?>">
<label>First Name</label>
<input type="text" name="fn" class="form-control" value="<?php echo $fn; ?>">
<span class="help-block"><?php echo $fn_err; ?></span>
</div>
<div class="form-group <?php echo (!empty($ln_err)) ? 'has-error' : ''; ?>">
<label>Last Name</label>
<input type="text" name="ln" class="form-control" value="<?php echo $ln; ?>">
<span class="help-block"><?php echo $ln_err; ?></span>
</div>
<div class="form-group <?php echo (!empty($email_err)) ? 'has-error' : ''; ?>">
<label>Email</label>
<input type="email" name="email" class="form-control" value="<?php echo $email; ?>">
<span class="help-block"><?php echo $email_err; ?></span>
</div>
<div class="form-group <?php echo (!empty($password_err)) ? 'has-error' : ''; ?>">
<label>Password</label>
<input type="password" name="password" class="form-control" value="<?php echo $password; ?>">
<span class="help-block"><?php echo $password_err; ?></span>
</div>
<div class="form-group <?php echo (!empty($confirm_password_err)) ? 'has-error' : ''; ?>">
<label>Confirm Password</label>
<input type="password" name="confirm_password" class="form-control" value="<?php echo $confirm_password; ?>">
<span class="help-block"><?php echo $confirm_password_err; ?></span>
</div>
<div class="form-group">
<input type="submit" class="btn btn-primary" value="Submit">
</div>
</form>
</div>
</div>
<script src="https://code.jquery.com/jquery-3.5.1.js" integrity="sha256-QWo7LDvxbWT2tbbQ97B53yJnYU3WhH/C8ycbRAkjPDc=" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
<script src="js/bootstrap.js"></script>
</body>
</html>