-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsignup.php
209 lines (197 loc) · 9.23 KB
/
signup.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
<!DOCTYPE html>
<html lang="en" class="gr__preview_uideck_com">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link rel="stylesheet" type="text/css" href="./assets/css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="./assets/css/line-icons.css">
<link rel="stylesheet" type="text/css" href="./assets/css/slicknav.css">
<link rel="stylesheet" type="text/css" href="./assets/css/nivo-lightbox.css">
<link rel="stylesheet" type="text/css" href="./assets/css/animate.css">
<link rel="stylesheet" type="text/css" href="./assets/css/owl.carousel.css">
<link rel="stylesheet" type="text/css" href="./assets/css/main.css">
<link rel="stylesheet" type="text/css" href="./assets/css/responsive.css">
<link rel="stylesheet" id="colors" href="./assets/css/green.css" type="text/css">
</head>
<?php
session_start();
include "connect.php";
if (isset($_SESSION['key'])) {
header("Location: ./user_home.php");
} elseif (isset($_POST['signup'])) {
$username = pg_escape_string($connection, $_POST['username']);
$fullname = pg_escape_string($connection, $_POST['fullname']);
$email = pg_escape_string($connection, $_POST['email']);
$phonenumber = (int)pg_escape_string($connection, $_POST['phonenumber']);
$password = pg_escape_string($connection, $_POST['password']);
$username_query = "SELECT username FROM account where username='" . $username . "'";
$email_query = "SELECT email FROM account where email='" . $email . "'";
$username_result = pg_query($connection, $username_query);
$username_num_results = pg_num_rows($username_result);
$email_result = pg_query($connection, $email_query);
$email_num_results = pg_num_rows($email_result);
if ($username_num_results >= 1) {
$display = "<div class='alert alert-danger text-center'><strong>The username (" . $username . ") has already been taken</strong></div>";
unset($username);
} elseif ($email_num_results >= 1) {
$display = "<div class='alert alert-danger text-center'><strong>The email (" . $email . ") has already been taken</strong></div>";
unset($username);
} else {
$signup_query = "insert into account( username, password, role, full_name, phone, email) values('" . $username . "','" . hash(sha256, $password) . "','user','" . $fullname . "','" . $phonenumber . "', '" . $email . "')";
$signup_result = pg_query($connection, $signup_query);
if ($signup_result) {
// Sign up successful
$display = "<div class='alert alert-success text-center'><strong>Account Created Successfully!</strong></div>";
header("refresh:2; url=./user_home.php");
$_SESSION['key'] = $username;
} else {
$display = "<div class='alert alert-danger text-center'><strong>Something seems to be wrong, please try later</strong></div>";
unset($username);
}
}
}
include "header.php";
?>
<div class="page-header" style="background: url(assets/img/banner1.jpg);">
<div class="container">
<div class="row">
<div class="col-md-12">
<div class="breadcrumb-wrapper">
<h2 class="product-title">Join Us
</h2>
<ol class="breadcrumb">
<li>
<a href="./index.php#">Home /
</a>
</li>
<li class="current">Register
</li>
</ol>
</div>
</div>
</div>
</div>
</div>
<?php echo $display ?>
<section class="register section-padding">
<div class="container">
<div class="row justify-content-center">
<div class="col-lg-5 col-md-12 col-xs-12">
<div class="register-form login-area">
<h3>
Register
</h3>
<form class="login-form" data-toggle="validator" role="form" action="signup.php" method="post">
<div class="form-group has-feedback">
<div class="form-group">
<div class="input-icon">
<i class="lni-user">
</i>
<input type="text" id="username" name="username" class="form-control"
placeholder="Username" required>
</div>
<div class="help-block with-errors">
<?php echo "<span style='color:red;'>$username_message</span>" ?>
</div>
</div>
<div class="form-group">
<div class="input-icon">
<i class="lni-user">
</i>
<input type="text" id="full_name" name="fullname" class="form-control"
placeholder="Full Name" required>
</div>
<div class="help-block with-errors">
</div>
</div>
<div class="form-group">
<div class="input-icon">
<i class="lni-envelope">
</i>
<input type="email" id="email" name="email" class="form-control"
placeholder="Email Address" data-error="Bruh, that email address is invalid"
required>
</div>
<div class="help-block with-errors">
<?php echo "<span style='color:red;'>$email_message</span>" ?>
</div>
</div>
<div class="form-group">
<div class="input-icon">
<i class="lni-phone">
</i>
<input type="text" pattern="\d{8}" id="phonenumber" name="phonenumber"
class="form-control" placeholder="Phone Number" required>
</div>
<div class="help-block with-errors">
</div>
</div>
<div class="form-group">
<div class="input-icon">
<i class="lni-lock">
</i>
<input type="password" class="form-control" id="password" name="password"
placeholder="Password" required>
</div>
<div class="help-block with-errors">
</div>
</div>
<div class="form-group">
<div class="input-icon">
<i class="lni-lock">
</i>
<input type="password" class="form-control" id="confirm_password"
data-match="#password" data-match-error="Whoops, these don't match"
placeholder="Retype Password" required>
</div>
<div class="help-block with-errors">
</div>
</div>
<div class="form-group mb-3">
</div>
<div class="text-center">
<button class="btn btn-common log-btn" name="signup" type="submit">Register
</button>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</section>
<?php
include "footer.php";
?>
<a href="./signup.php#" class="back-to-top">
<i class="lni-chevron-up">
</i>
</a>
<div id="preloader" style="display: none;">
<div class="loader" id="loader-1">
</div>
</div>
<script src="./assets/js/jquery-min.js">
</script>
<script src="./assets/js/popper.min.js">
</script>
<script src="./assets/js/bootstrap.min.js">
</script>
<script src="./assets/js/jquery.counterup.min.js">
</script>
<script src="./assets/js/waypoints.min.js">
</script>
<script src="./assets/js/wow.js">
</script>
<script src="./assets/js/owl.carousel.min.js">
</script>
<script src="./assets/js/nivo-lightbox.js">
</script>
<script src="./assets/js/jquery.slicknav.js">
</script>
<script src="./assets/js/main.js">
</script>
<script src="./assets/js/form-validator.min.js">
</script>
</body>
</html>