-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsignup.php
308 lines (266 loc) · 11.2 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
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
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
<?php
session_start();
if(isset($_SESSION['username']))
{
if($_SESSION['username']=="admin")
{
header("location: admin_home.php");
exit;
}
else
header("location: dashboard.php");
exit;
}
require_once "config.php";
$username = $password = $confirm_password = "";
$username_err = $password_err = $confirm_password_err = "";
$tnc_err = "";
if ($_SERVER['REQUEST_METHOD'] == "POST"){
// Check if username is empty
if(empty(trim($_POST["username"]))){
$username_err = "Username cannot be blank";
}
else{
$sql = "SELECT uid FROM users WHERE username = ?";
$stmt = mysqli_prepare($conn, $sql);
if($stmt)
{
mysqli_stmt_bind_param($stmt, "s", $param_username);
// Set the value of param username
$param_username = trim($_POST['username']);
// Try to execute this statement
if(mysqli_stmt_execute($stmt)){
mysqli_stmt_store_result($stmt);
if(mysqli_stmt_num_rows($stmt) == 1)
{
$username_err = "This username is already taken";
}
else{
$username = trim($_POST['username']);
$email = trim($_POST['email']);
$mobileno = trim($_POST['mobileno']);
$name = trim($_POST['name']);
}
}
else{
echo "Something went wrong";
}
}
}
mysqli_stmt_close($stmt);
if(!isset($_POST['tnc']))
{
$tnc_err="Please accept the terms and conditions.";
}
// Check for password
if(empty(trim($_POST['password']))){
$password_err = "Password cannot be blank";
}
elseif(strlen(trim($_POST['password'])) < 5){
$password_err = "Password cannot be less than 5 characters.";
}
else{
$password = trim($_POST['password']);
}
// Check for confirm password field
if(trim($_POST['password']) != trim($_POST['confirm_password'])){
$password_err = "Passwords should match";
}
// If there were no errors, go ahead and insert into the database
if(empty($username_err) && empty($password_err) && empty($confirm_password_err) && empty($tnc_err))
{
$sql = "INSERT INTO users (username,name, password,email,mobileno) VALUES (?,?,?,?,?)";
$stmt = mysqli_prepare($conn, $sql);
if ($stmt)
{
mysqli_stmt_bind_param($stmt, "sssss", $param_username,$param_name ,$param_password,$param_email,$param_mobileno);
// Set these parameters
$param_username = $username;
$param_password = password_hash($password, PASSWORD_DEFAULT);
$param_email = $email;
$param_mobileno = $mobileno;
$param_name = $name;
// Try to execute the query
if (mysqli_stmt_execute($stmt))
{
header("location: login.php");
}
else{
echo "Something went wrong... cannot redirect!";
}
}
mysqli_stmt_close($stmt);
}
mysqli_close($conn);
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>CrypTrack Register</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.2/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-Zenh87qX5JnK2Jl0vWa8Ck2rdkQ2Bzep5IDxbcnCeuOxjzrPF/et3URy9Bv1WTRi" crossorigin="anonymous">
<link rel="stylesheet" href="css/styling-aboutme.css">
<link rel="stylesheet" href="css/responsive-about-us.css">
<link rel="stylesheet" href="css/utils.css">
<link rel="stylesheet" href="css/fonts/fontstyle.css">
<link rel="stylesheet" href="css/fonts/stylesheet.css">
<link rel="stylesheet" href="css/common-assets.css">
<link rel="stylesheet" href="css/styling-signup.css">
</head>
<body>
<main>
<div class="main-div-flex">
<div class="heading-flex">
<h1>Register on</h1>
<a href="index.php" ><img src="img/logo.png" alt="" id="home-logo"></a>
</div>
<div class="register-flex">
<div class="register-left">
<div class="register-left-sub-heading">
<h4 style="display:flex;" >New to Crypto?</h4>
<h4 style="display:flex;" >Learning Crypto?</h4>
<h4 style="display:flex;" >Analysing Crypto?</h4>
</div>
<h2 class="register-left-main-heading"r>Dont worry! CrypTrack has got you covered!</h2>
<p class="register-left-paragraph">
Whether you are new to the crypto world, or an ace trader who only focuses only on key aspects, we satisfy the needs of the traders on both ends of the spectrum.
</p>
<p class="register-left-ul-heading">Sign up today at CrypTrack to get access to:</p>
<div class="register-left-bottom-flex">
<ul>
<li>Real-time crypto info</li>
<li>CrypTrade™ (Mock Trade)</li>
<li>Crypto Converter</li>
<li>News</li>
<li>Beginner Friendly Charts</li>
</ul>
<img src="img/signup/hand.png" alt="">
</div>
</div>
<div class="register-right">
<div class="register-form-flex">
<h4>Enter your details</h4>
<form action="" method="post" onsubmit="return validatesignup(this)">
<div class="general-input">
Name
<input type="text" name="name" id="field" placeholder="Name">
</div>
<div class="general-input">
User Name*
<input type="text" name="username" id="field" placeholder="UserName">
</div>
<div class="general-input">
Email ID
<input type="text" name="email" id="field" placeholder="Email ID">
</div>
<div class="password-flex">
<div class="password-inner-flex">
Password* (atleast 5 characters)
<input type="password" name="password" id="field-2" placeholder="Password">
</div>
<div class="password-inner-flex">
Re-type Password*
<input type="password" name="confirm_password" id="field-2"
placeholder="Re-type Password">
</div>
</div>
<div class="general-input">
Mobile No
<input type="text" name="mobileno" id="field" placeholder="Mobile No">
</div>
<div class="error-message-hidden">
<div class="error-message" id="err-msg">
<?php
// if(empty($username_err) && empty($password_err) && empty($confirm_password_err))
echo $username_err.'<br/>';
echo $password_err.'<br/>';
echo $confirm_password_err.'<br/>';
?>
</div>
</div>
<div class="sign-up">
<div class="sign-up-checkbox">
<div>
<input type="checkbox" name="tnc" id="chk-bx">I agree to the <a href="tnc.php" target="_blank" id="tnc-agreement">terms and conditions*</a>
</div>
<div class="error-message-text tnc-error">
<?php echo $tnc_err.'<br/>';?>
</div>
</div>
<input type="submit" name="submit " id="submit" value="Sign Up">
</div>
</form>
</div>
</div>
</div>
</div>
</main>
<script>
function validatesignup(thisform)
{
var emailid_regex="^[a-zA-Z0-9+_.-]+@[a-zA-Z0-9.-]+$";
var err_box=document.getElementById("err-msg");
username=thisform.username.value;
password=thisform.password.value;
confirm_password=thisform.confirm_password.value;
mobileno=thisform.mobileno.value;
emailid=thisform.email.value;
if(username=="" || username==null)
{
alert("Enter a username.")
return false;
}
if(isNaN(mobileno))
{
alert("Enter a valid mobile number.")
thisform.mobileno.focus();
return false;
}
if(mobileno.length!=10)
{
alert("Mobile number must be 10 digits long.")
thisform.mobileno.focus();
return false;
}
if(!emailid.match(emailid_regex))
{
alert("Enter a valid email id.")
thisform.email.focus();
return false;
}
if(password.length<5)
{
alert("Password should be atleast 5 characters long.")
thisform.password.focus();
return false;
}
if(confirm_password.length<5)
{
alert("Confirm password should be atleast 5 characters long.")
thisform.password.focus();
return false;
}
if(password.length>=5 && confirm_password.length>=5)
{
if(confirm_password!=password)
{
alert("Passwords do not match.")
thisform.password.focus();
return false;
}
}
let checkbox = document.getElementById("chk-bx");
if(!checkbox.checked)
{
alert("Please accept the terms and conditions.")
return false;
}
return true;
}
</script>
</body>
</html>