-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsignup.php
255 lines (219 loc) · 11.4 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
<?php
define('MYSITE', true);
include 'db/dbconnect.php';
$title = 'Signup';
$css_directory = 'css/main.min.css';
$css_directory2 = 'css/main.min.css.map';
include 'includes/header.php';
include 'includes/navbar.php';
?>
<?php
$showAlert = false;
$showError = false;
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$first_name = $_POST["firstname"];
$last_name = $_POST["lastname"];
$email = $_POST["email"];
$phone = $_POST["phone"];
$address = $_POST["address"];
$city_name = $_POST["city"];
$pincode = $_POST["pincode"];
$username = $_POST["username"];
$password = $_POST["password"];
$cpassword = $_POST["cpassword"];
$existsql = "SELECT * FROM `login` where username ='$username' ";
$existresult = mysqli_query($conn, $existsql);
$numexist = mysqli_num_rows($existresult);
if ($numexist > 0) {
$showError = "Username is already existing.";
}
else {
if ($password == $cpassword ) {
$hash = password_hash($password, PASSWORD_DEFAULT);
// insert into LOGIN TABLE only USERNAME & PASSWORD.
$sql = "INSERT INTO `login` (`login_id` , `role_id`, `username`,`password`) VALUES ('', '3', '$username', '$hash')";
$result = mysqli_query($conn, $sql);
if ($result) {
//fetch login id from login table.
$fetch_loginid = "SELECT `login_id` FROM `login` where username ='$username'";
$fetch_result = mysqli_query($conn, $fetch_loginid);
$login_row = mysqli_fetch_assoc($fetch_result);
$login_id = $login_row['login_id'];
//fetch city is from city table.
$fetch_cityid = "SELECT `city_id` FROM `city` where city_name ='$city_name'";
$fetch_city_result = mysqli_query($conn, $fetch_cityid);
$city_row = mysqli_fetch_assoc($fetch_city_result);
$city_id = $city_row['city_id'];
$sql2 = "INSERT INTO `customer` (`customer_id`, `login_id`, `first_name`, `last_name`, `email`, `phone`, `address`, `city_id`, `pincode`) VALUES ('', '$login_id', '$first_name', '$last_name','$email','$phone', '$address', '$city_id', '$pincode')";
$result2 = mysqli_query($conn, $sql2);
if ($result2) {
$showAlert = "Your account is now created.";
}
} else {
$showError = "Something went wrong!";
}
}
else {
$showError = "Password do no match!";
}
}
}
?>
<body style="background-image: linear-gradient(-145deg,#f5faff,#87b0de);">
<?php
if ($showAlert) {
echo '<div class="alert alert-success alert-dismissible fade show" role="alert">
<strong>Success! </strong> ' . $showAlert .'
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>';
}
if ($showError) {
echo '<div class="alert alert-danger alert-dismissible fade show" role="alert">
<strong>Success! </strong> ' . $showError .'
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>';
}
?>
<!-- container -->
<div class="container">
<div class="mx-auto" style="width: 75%; border: 1px solid #1C315E; padding: 3em;">
<h4 class="pb-2 text-c1-1">Enter the details for order service </h4>
<div class="bg-c1-1" style="width:370px; height: 3px; margin-top:-10px;"></div>
<hr class="pt-3">
<form class="needs-validation" action="<?php echo $_SERVER['PHP_SELF'] ?>" method="post" novalidate>
<!-- name & email line -->
<div class="form-row">
<div class="form-group col-md-6 input-group-sm">
<label for="firstname">First Name:-</label>
<input type="text" class="form-control " id="firstname" name="firstname" required>
<!-- <div class="valid-feedback">
Looks good!
</div> -->
</div>
<div class="form-group col-md-6 input-group-sm">
<label for="lastname">Last Name:-</label>
<input type="text" class="form-control" id="lastname" name="lastname" required>
</div>
<div class="form-group col-md-6 input-group-sm">
<label for="email">Email:-</label>
<input type="email" class="form-control" id="spemail" name="email" aria-describedby="emailFeedback" required>
<div id="emailFeedback" class="invalid-feedback">
Please provide a valid email.
</div>
</div>
<div class="form-group col-md-6 input-group-sm">
<label for="phone">Phone No.:-</label>
<input type="tel" class="form-control" required pattern="^[0-9-+\s()]{10}" name="phone" aria-describedby="phoneFeedback" data-for="phoneNumber">
<!-- <input type="tel" class="form-control" required pattern="\d{10}" data-for="phoneNumber" name="phone" aria-describedby="phoneFeedback" > -->
<div id="phoneFeedback" class="invalid-feedback">
Please provide a valid Phone number.
</div>
</div>
</div>
<!-- Address line -->
<div class="form-row">
<div class="mb-3 col-12">
<label for="validationTextarea">Address:-</label>
<textarea class="form-control" id="validationTextarea" name="address" placeholder="Enter your home address" required></textarea>
<div class="invalid-feedback">
Please enter your address.
</div>
</div>
</div>
<!-- city line -->
<div class="form-row">
<div class="form-group col-md-4 input-group-sm">
<label for="city">City:-</label>
<select id="city" class=" custom-select" name="city" required>
<option value="">Choose City</option>
<?php // category view code. Data get from category table
$sql = "SELECT * FROM `city`
";
$result = mysqli_query($conn, $sql);
if ($result) {
while ($row = mysqli_fetch_assoc($result)) {
$city_name = $row['city_name'];
echo '<option value="' . $city_name . '">' . $city_name . '</option>';
}
}
?>
<!-- <option value="two">.this..</option>
<option value="three">.and..</option>
<option value="five">.that..</option> -->
</select>
<div class="invalid-feedback">Please choose a city.</div>
</div>
<div class="form-group col-md-2 input-group-sm">
<label for="Pincode">Pincode:-</label>
<input type="text" class="form-control" name="pincode" pattern="\d{6}" id="pincode" required>
</div>
</div>
<hr class="mt-4 mb-4">
<!-- usename line -->
<div class="form-row mt-4">
<div class="form-group col-md-6 ">
<label for="inlineFormInputGroupUsername2">Create Username:-</label>
<div class="input-group mb-2 mr-sm-2 input-group-sm">
<div class="input-group-prepend">
<div class="input-group-text bg-c1-1 text-light">@</div>
</div>
<input type="text" class="form-control" pattern="(?=.*[a-z]).{4,}" id="username" name="username" placeholder="deep_13" aria-describedby="inputGroupPrepend" required>
<div class="invalid-feedback">
Please choose a right username.
</div>
</div>
</div>
</div>
<!-- password line -->
<div class="form-row">
<div class="form-group col-md-6 input-group-sm">
<label for="password">Create Password:-</label>
<!-- <input type="password" class="form-control" id="password" name="password" required> -->
<input type="password" class="form-control" id="password" name="password" pattern="(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{8,}" required>
<div id="phoneFeedback" class="invalid-feedback">
Must contain at least one number and one uppercase and lowercase letter, and at least 8 or
more characters.
</div>
</div>
<div class="form-group col-md-6 input-group-sm">
<label for="confirmpassword">Confirm Password:-</label>
<!-- <input type="password" class="form-control" id="cpassword" name="cpassword" required> -->
<input type="password" class="form-control" id="cpassword" name="cpassword" pattern="(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{8,}" required>
<div id="phoneFeedback" class="invalid-feedback">
Password does not matched.
</div>
</div>
</div>
<a href=""><button type="submit" class="btn pest_btn btn-c1-1">Sign in</button></a>
<a href="index.php" class="btn btn-outline-secondary">Cancel</a>
</form>
</div>
</div>
<!-- form validation feedback -->
<script>
// Example starter JavaScript for disabling form submissions if there are invalid fields
(function() {
'use strict';
window.addEventListener('load', function() {
// Fetch all the forms we want to apply custom Bootstrap validation styles to
var forms = document.getElementsByClassName('needs-validation');
// Loop over them and prevent submission
var validation = Array.prototype.filter.call(forms, function(form) {
form.addEventListener('submit', function(event) {
if (form.checkValidity() === false) {
event.preventDefault();
event.stopPropagation();
}
form.classList.add('was-validated');
}, false);
});
}, false);
})();
</script>
<?php
include 'includes/footer.php';
?>