-
Notifications
You must be signed in to change notification settings - Fork 0
/
registration.php
364 lines (302 loc) · 10.6 KB
/
registration.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
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
<?php
$success=0;
$user=0;
if($_SERVER['REQUEST_METHOD']=='POST'){
include 'connect1.php';
$username = $_POST['username'];
$mailid = $_POST['email'];
$password = $_POST['password'];
$number = $_POST['num'];
//image file operations
$targetDir = "./uploads/"; // Directory to store uploaded images
$targetFile = $targetDir . basename($_FILES["image"]["name"]);
$uploadOk = 1;
$imageFileType = strtolower(pathinfo($targetFile, PATHINFO_EXTENSION));
// Check if image file is a actual image or fake image
if (isset($_POST["submit"])) {
$check = getimagesize($_FILES["image"]["tmp_name"]);
if ($check !== false) {
echo "File is an image - " . $check["mime"] . ".";
$uploadOk = 1;
} else {
echo "File is not an image.<br>";
$uploadOk = 0;
}
}
// Check if file already exists
if (file_exists($targetFile)) {
echo "Sorry, file already exists.<br>";
$uploadOk = 0;
}
// Check file size
if ($_FILES["image"]["size"] > 50000000) {
echo "Sorry, your file is too large.<br>";
$uploadOk = 0;
}
// Allow only certain image file formats
$allowedFormats = array("jpg", "jpeg", "png", "gif");
if (!in_array($imageFileType, $allowedFormats)) {
echo "Sorry, only JPG, JPEG, PNG & GIF files are allowed.<br>";
$uploadOk = 0;
}
// Check if $uploadOk is set to 0 by an error
if ($uploadOk == 0) {
echo "Sorry, your file was not uploaded.<br>";
} else {
if (move_uploaded_file($_FILES["image"]["tmp_name"], $targetFile)) {
echo "The file " . basename($_FILES["image"]["name"]) . " has been uploaded.<br>";
} else {
echo "Sorry, there was an error uploading your file.<br>";
}
}
/* $file = $_FILES['file'];
$filename = $_FILES['file']['name'];
$filetmpname = $_FILES['file']['tmp_name'];
$filesize = $_FILES['file']['size'];
$fileerror = $_FILES['file']['error'];
$filetype = $_FILES['file']['type'];
$fileExt= explode('.', $filename);
$fileactualext = strtolower(end($fileExt));
$allowed = array('jpg','jpeg','png','pdf');
if(in_array($fileactualext, $allowed)){
if($fileerror === 0){
if($filesize < 50000000){
$filenamenew = uniqid('IMG-', true).".".$fileactualext;
$filedestination = 'uploads/'.$filenamenew;
move_uploaded_file($filetmpname,$filedestination);
header("location:login.php?uploadsuccess");
}else
{
echo "your file is too large";
}
}else{
echo "There was an error while uploading your file";
}
}else{
echo "you cannot upload files of this type!";
}
*/
$country = $_POST['country'];
$state = $_POST['state'];
$pincode = $_POST['pin'];
$sql = "select * from `Registration1` where
username='$username'";
$result = mysqli_query($conn,$sql);
if($result){
$num = mysqli_num_rows($result);
if($num>0){
//echo "username already exists";
$user=1;
}else{
$sql = "insert into `Registration1`(username,email,password,mobile,image,country,state,pincode)
values('$username','$mailid','$password','$number','$targetFile','$country','$state','$pincode')";
$result = mysqli_query($conn,$sql);
if($result){
echo "Congratulations " .$username. "<br>";
$success=1;
}else{
die(mysqli_error($conn));
}
}
}
}
if($user){
echo '<div class="alert alert-danger alert-dismissible fade show" role="alert">
<strong>Ohh no sorryy</strong> user already exists
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>';
}
//background-image: url(./uploads/carimg/5.jpg)
if($success){
echo '<div class="alert alert-success alert-dismissible fade show" role="alert">
<strong></strong> <br>your Registration is successfully done!";
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>';
echo "<h1>Form Data</h1>";
echo "<p><strong>Username:</strong> $username</p>";
echo "<p><strong>Email:</strong> $email</p>";
echo "<p><strong>Mobile Number:</strong> $mobile</p>";
}
?>
<!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">
<link rel="stylesheet" href="css/bootstrap.min.css">
<script src="js/bootstrap.bundle.min.js"></script>
<title>Farmer registration</title>
<style>
*{
margin: 0;
padding: 0;
box-sizing: border-box;
}
body{
justify-content: center;
align-items: center;
height: 100vh;
}
select{
cursor: pointer;
width: 300px;
height: 40px;
border-radius: 15px;
background-color: rgb(250, 250, 250);
box-shadow: 2px 4px 8px #c5c5c5;
border: darkslategray;
outline: dimgrey;
margin-top: 30px;
}
.registration {
position: relative;
top: 80%;
left: 50%;
transform: translate(-50%, -50%);
width: 650px;
}
.registration h1{
font-size: 40px;
text-align: center;
text-transform: uppercase;
margin: 40px;
}
.registration input{
font-size: 16px;
padding: 15px 10px;
width: 100%;
border: 0;
border-radius: 0px;
outline: none;
}
</style>
</head>
<body >
<?php
?>
<!-- <div class="container mt-5">
<br>
<br>
-->
<div class="container-fluid">
<h1 ><u>New farmer registration</u></h1>
<form action="/crud/project_S/registration1.php" method="POST"
enctype="multipart/form-data" id="myForm">
<div class="form-group">
<label for="username">Username:</label>
<input type="text" class="form-control" id="username" name="username" >
</div>
<br>
<div class="form-group">
<label for="email">Email:</label>
<input type="email" class="form-control" id="email" name="email" >
</div>
<br>
<div class="form-group">
<label for="password">Password:</label>
<input type="password" class="form-control" id="password" name="password" >
</div>
<br>
<div class="form-group">
<label for="cpassword">Confirm Password:</label>
<input type="password" class="form-control" id="cpassword" name="cpassword" >
</div>
<br>
<div class="form-group">
<label for="num">Mobile</label>
<input type="tel" class="form-control" id="num" name="num" >
</div>
<br>
<div class="form-group">
<label for="file">Image:</label>
<input type="file" class="form-control" id="file" name="image" accept="image/*" >
</div>
<br>
<!-- country and state-->
<div class="wrapper">
<select name ="country" id="countries">
<option value="-1">Select country</option>
<option value="India">India</option>
<option value="srilanka">Sri Lanka</option>
<option value="bangladesh">Bangladesh</option>
<option value="israel">Israel</option>
</select>
<select name="state" id="states">
<option value="-1">Select state</option>
</select>
</div>
<script>
let countrystates=[
{
country:"India",
code:"India",
states:["Andhra pradesh","Arunachal pradesh","Assam","Bihar","chattisgarh","Haryana","TamilNadu","Karnakata","Telangana"]
},
{
country:"Srilanka",
code:"srilanka",
states:["central","western","north"]
},
{
country:"Bangladesh",
code:"bangladesh",
states:["Barishal","Chattogram","Dhaka" ," Khulna"," Rajshahi", " Rangpur", "Mymensingh","Sylhet"]
},
{
country:"israel",
code:"israel",
states:["western","north central","central"]
}
]
let countryselect = document.querySelector('#countries');
let stateselect = document.querySelector('#states');
countryselect.onchange = function(){
stateselect.options.length=0;
if(countryselect.value!=-1){
for(ele of countrystates){
if(countryselect.value == ele.code){
let states = ele.states
let op = document.createElement('option')
op.value = -1;
op.innerText = "Select State";
stateselect.options[0] = op;
let i=1;
for(state of states){
let op = document.createElement('option')
op.value = state;
op.innerText = state;
stateselect.options[i] = op;
i++
}
}
}
}
}
</script>
<!--<div class="form-group">
<label for="country">country</label>
<input type="text" class="form-control" id="country" name="country" required>
</div>
<br>
<div class="form-group">
<label for="state">state</label>
<input type="text" class="form-control" id="state" name="state" required>
</div> -->
<br>
<div class="form-group">
<label for="pin">pincode</label>
<input type="number" class="form-control" id="pin" name="pin" >
</div>
<div>
<button type="submit" class="btn btn-primary w-100">Register</button>
</div>
</form>
</div>
<script src="formvalidate.js"></script>
</body>
</html>