forked from ABHRADEEP800/PHP-E_Commerce_Project
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsignup.php
executable file
·253 lines (227 loc) · 8.43 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
<?php
session_start();
// including database file
include 'database.php';
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<title>Signup</title>
<link rel="icon" type="image/x-icon" href="assets/svg-logo/logo1.svg">
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="stylesheet" type="text/css" media="screen" href="main.css" />
<link
rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/css/bootstrap.min.css"
/>
<script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.2.2/dist/js/bootstrap.bundle.min.js"></script>
<script
src="https://kit.fontawesome.com/db79afedbd.js"
crossorigin="anonymous"
></script>
<script src="jquery.js"></script>
</head>
<body>
<!----------------------------------header -------------------------- -->
<?php
// including header file
include 'header.php';
?>
<!-------------------------------------------------body----------------------------------------------------------->
<!------------------------- css ----------------------------->
<style>
.divider:after,
.divider:before {
content: "";
flex: 1;
height: 1px;
background: #eee;
}
.h-custom {
height: calc(100% - 73px);
}
@media (max-width: 450px) {
.h-custom {
height: 100%;
}
}
</style>
<!----------------------------------- main body -------------------------------->
<section>
<div class="container-fluid h-custom">
<div class="row d-flex justify-content-center align-items-center">
<div class="col-md-9 col-lg-6 col-xl-5">
<img
src="assets/image/seller_login.png"
class="img-fluid"
alt="Sample image"
/>
</div>
<div class="col-md-8 col-lg-6 col-xl-4 offset-xl-1">
<form method="post">
<div class="divider d-flex align-items-center mb-4">
<h2 class="text-center">Signup</h2>
</div>
<!-- Name input -->
<div class="d-flex ">
<div class="form-outline pe-1 col-6 mb-4">
<label class="form-label" for="form3Example3"
>First Name</label
>
<input
type="text"
name="fname"
id="form3Example3"
class="form-control form-control-lg"
placeholder="Enter your First name" required
/>
</div>
<div class="form-outline ps-1 col-6 mb-4">
<label class="form-label" for="form3Example3"
>Last Name</label
>
<input
type="text"
name="lname"
id="form3Example3"
class="form-control form-control-lg"
placeholder="Enter your Last name" required
/>
</div>
</div>
<!-- Email input -->
<div class="form-outline mb-4">
<label class="form-label" for="form3Example3"
>Email address</label
>
<input
type="email"
id="form3Example3"
class="form-control form-control-lg"
name="email"
placeholder="Enter a valid email address" required
/>
</div>
<!-- Password input -->
<div class="form-outline mb-3">
<label class="form-label" for="form3Example4">Password</label>
<input
type="password"
name="pass"
id="form3Example4"
class="form-control form-control-lg"
placeholder="Enter password" required
/>
</div>
<!-- Confirm Password input -->
<div class="form-outline mb-3">
<label class="form-label" for="form3Example4"
>Confirm Password</label
>
<input
type="password"
name="cpass"
id="form3Example4"
class="form-control form-control-lg"
placeholder="Retype password" required
/>
</div>
<!-- User Type -->
<label class="form-label">Choose User Type</label>
<select class="form-select" name="utype" aria-label="select example">
<option value="Customer">Customer</option>
<option value="Seller">Seller</option>
</select>
<!-- captcha -->
<div class="form-outline mb-3">
<label class="form-label" for="form3Example4">Captcha</label><br>
<img src="captcha.php" alt="captcha" /><br><br>
<!-- captcha input -->
<input type="text" name="captcha" id="form3Example4" class="form-control form-control-lg"
placeholder="Enter Captcha Code" required />
</div>
<!-- Submit button -->
<div class="text-center text-lg-start mt-4 pt-2">
<button
type="submit"
name="signup"
class="btn btn-primary btn-lg"
style="padding-left: 2.5rem; padding-right: 2.5rem"
>
Register
</button>
</div>
</form>
</div>
</div>
</div>
</section>
<?php
// check if signup button is clicked
if(isset($_POST['signup'])){
// check if captcha is correct
if($_SESSION['captcha'] == $_POST['captcha']){
// checking for empty fields
if(($_POST['email'] == "") || ($_POST['pass'] == "") || ($_POST['cpass'] == "") || ($_POST['utype'] == "") || ($_POST['fname'] == "") || ($_POST['lname'] == "")){
echo "<script>alert('Please fill all the fields')</script>";
echo "<script>window.location='/signup.php'</script>";
}
// if all fields are not empty
else{
// taking form data into variables
$email=$_POST['email'];
$pass=$_POST['pass'];
$cpass=$_POST['cpass'];
$utype=$_POST['utype'];
$name=$_POST['fname']." ".$_POST['lname'];
// check if email already exists
$sql=
"SELECT * FROM `user` WHERE `user_email`='$email'";
$result=mysqli_query($conn,$sql);
$num=mysqli_num_rows($result);
// if email already exists
if($num==1){
echo "<script>alert('Email Already Exists')</script>";
echo "<script>window.location='/signup.php'</script>";
} // end of if
// if email does not exists
else{
// check if password and confirm password matches
if($pass==$cpass){
// encrypting password
$pass=md5($pass);
// inserting data into database
$query="INSERT INTO `user`(`user_email`,`user_name`, `user_pass`, `user_type`) VALUES ('$email','$name','$pass','$utype')";
$result=mysqli_query($conn,$query);
//
if($result){
unset($_SESSION['captcha']);
echo "<script>alert('Registered Successfully')</script>";
echo "<script>window.location='/login.php'</script>";
}
else{
echo "<script>alert(' Registration Failed')</script>";
}
}
else{
echo "<script>alert('Password and Confirm Password does not match')</script>";
}
}
}
}
// if captcha does not match
else{
echo "<script>alert('Captcha does not match')</script>";
}
}
?>
<!-----------------------footer ------------------------>
<?php
// including footer file
include 'footer.php';
?>
</body>
</html>