-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUniversal2.php
More file actions
269 lines (217 loc) · 10.5 KB
/
Universal2.php
File metadata and controls
269 lines (217 loc) · 10.5 KB
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
<?php
include_once ('db_connection.php');
//-------------------------- Universal Registration code------------------------------------
if (isset($_POST['registerbtn'])) {
$error_message = "";
$success_message = "";
//$type_of_account = trim($_POST['type_of_account']);
$type_of_account = 'Student';
$name = trim($_POST['name']);
$email = trim($_POST['email']);
// $gender = trim($_POST['gender']);
// $dob = $_POST['dob'];
// $ph_no = trim($_POST['ph_no']);
// $address = trim($_POST['address']);
// $aadhaar_no = trim($_POST['aadhaar_no']);
// $aadhaar_upload = $_FILES['aadhaar_upload'];
$password = trim($_POST['password']);
$confirmpassword = trim($_POST['cpassword']);
$username = $email;
$isValid = true;
//echo "TOA:".$type_of_account;
// Check fields are empty or not
if ($name == '' || $email == '' || $password == '' || $confirmpassword == '') {
$isValid = false;
$error_message = "Please fill all fields.";
}
// Check if confirm password matching or not
if ($isValid && ($password != $confirmpassword)) {
$isValid = false;
$error_message = "Confirm password not matching.";
echo "<script>alert($error_message)</script>";
}
// Check if Email-ID is valid or not
if ($isValid && !filter_var($email, FILTER_VALIDATE_EMAIL)) {
$isValid = false;
$error_message = "Invalid Email-ID.";
}
// Check if Email-ID & Phone No already exists
if ($isValid) {
switch ($type_of_account) {
case 'Student':
$Valid_Message = 'OK';
$Valid_Message = char_validator('student_reg', 'email', $email, 'Email ID Already existing! Try again.');
if ($Valid_Message != 'OK') {
echo "<script>alert('$Valid_Message');</script>";
echo $Valid_Message;
$Valid_Message = 'OK';
$isValid = false;
}
$Valid_Message = char_validator('login', 'username', $email, 'Email ID Already existing! Try again.');
if ($Valid_Message != 'OK') {
echo "<script>alert('$Valid_Message');</script>";
echo $Valid_Message;
$Valid_Message = 'OK';
$isValid = false;
}
break;
default:
echo "Execution miss run at type of Account. Contact developer!";
$isValid = false;
break;
}
}
//Main SQL Insert records starts here
if ($isValid) {
switch ($type_of_account) {
case 'Student':
$RegTable = "student_reg";
$Reg_query = "INSERT INTO $RegTable(name,email,status) VALUES('$name','$email','Approved')";
echo $Reg_query;
$Register_SQL = mysql_query($Reg_query);
$Login_Query = "INSERT INTO login(username,password,name,type,account_status) VALUES('$email','$password','$name','$type_of_account','Approved')";
$Login_SQL = mysql_query($Login_Query);
echo $Login_Query;
if ($Register_SQL && $Login_SQL) {
// //members_info
// $Q2 = "INSERT INTO members_info(memail,status) VALUES('$email','New')"; echo $Q2;
// $X2 = mysql_query($Q2);
// //members_fitnessgoalss
// $Q3 = "INSERT INTO members_fitnessgoals(memail,status) VALUES('$email','New')"; echo $Q3;
// $X3 = mysql_query($Q3);
// //members_healthdata
// $Q4 = "INSERT INTO members_healthdata(memail,status) VALUES('$email','New')"; echo $Q4;
// $X4 = mysql_query($Q4);
// //members_trainer
// $Q5 = "INSERT INTO members_trainer(memail,status) VALUES('$email','New')"; echo $Q5;
// $X4 = mysql_query($Q5);
// if($X2 && $X3 && $X4)
// {
// echo "<script>alert('Account created successfully.!')</script>";
// echo "<script>location.href='index.php'</script>";
// }
// else{
// echo "<script>alert('Internal Execution error!')</script>";
// echo "<script>location.href='index.php'</script>";
// }
echo "<script>alert('Account created successfully.!')</script>";
echo "<script>location.href='index.php'</script>";
} else {
$error_message = "Registration failed due to any reason.";
echo "<script>alert('Registration failed due to any reason!')</script>";
echo "<script>location.href='index.php'</script>";
}
break;
case 'Trainer':
$RegTable = "acc_trainer";
$Reg_query = "INSERT INTO $RegTable(name,gender,temail,dob,ph_no,address,photo,aadhaar_no,aadhaar_doc,status)
VALUES('$name','$gender','$email','$dob',$ph_no,'$address','$photo',$aadhaar_no,'$aadhaar_doc','New')";
echo $Reg_query;
$Register_SQL = mysql_query($Reg_query);
$Login_Query = "INSERT INTO login(username,password,name,type,account_status) VALUES('$email','$password','$name','$type_of_account','New')";
$Login_SQL = mysql_query($Login_Query);
echo $Login_Query;
if ($Register_SQL && $Login_SQL) {
//trainer_info
$Q2 = "INSERT INTO trainer_info(temail,status) VALUES('$email','New')";
echo $Q2;
$X2 = mysql_query($Q2);
//trainer_performance
$Q3 = "INSERT INTO trainer_performance(temail,status) VALUES('$email','New')";
echo $Q3;
$X3 = mysql_query($Q3);
if ($X2 && $X3) {
echo "<script>alert('Account created successfully.!')</script>";
echo "<script>location.href='index.php'</script>";
} else {
echo "<script>alert('Internal Execution error!')</script>";
echo "<script>location.href='index.php'</script>";
}
} else {
$error_message = "Registration failed due to any reason.";
echo "<script>alert('Registration failed due to any reason!')</script>";
echo "<script>location.href='index.php'</script>";
}
default:
echo "<script>alert('Default error!')</script>";
echo "<script>location.href='index.php'</script>";
break;
}
} else {
//echo "<script>alert('Error!')</script>";
echo $error_message;
echo "Validation Failed";
}
}
//-------------------------- Universal Registration code-----------------xxxxxxxxxxx-------------------
//-------------------------- Universal login code------------------------------------
if (isset($_POST['loginbtn'])) {
$username = trim($_POST['username']);
$password = trim($_POST['password']);
$table = 'login';
$sql = "SELECT * FROM $table WHERE username = '$username' AND account_status = 'Approved'";
$result = mysql_query($sql);
if (mysql_num_rows($result) > 0) {
$row = mysql_fetch_assoc($result);
$Table_Password = $row['password'];
$type_of_user = $row['type'];
$name = $row['name'];
if ($password == $Table_Password) {
echo "<script>alert('Login successful! Welcome, $name.');</script>";
switch ($type_of_user) {
case 'Student':
echo "Student login success";
$_SESSION['username'] = $username;
$_SESSION['usertype'] = $type_of_user;
$_SESSION['name'] = $row['name'];
$_SESSION['account_status'] = $row['account_status'];
echo "<script>location.href='internal/Studentindex.php'</script>";
break;
case 'Admin':
$_SESSION['username'] = $username;
$_SESSION['usertype'] = $type_of_user;
$_SESSION['name'] = $row['name'];
$_SESSION['account_status'] = $row['account_status'];
echo "Admin login success!";
echo "<script>location.href='internal/Adminindex.php'</script>";
break;
case 'Faculty':
$_SESSION['username'] = $username;
$_SESSION['usertype'] = $type_of_user;
$_SESSION['name'] = $row['name'];
$_SESSION['account_status'] = $row['account_status'];
echo "Faculty login success!";
echo "<script>location.href='internal/Facultyindex.php'</script>";
break;
case 'Parent':
$_SESSION['username'] = $username;
$_SESSION['usertype'] = $type_of_user;
$_SESSION['name'] = $row['name'];
$_SESSION['account_status'] = $row['account_status'];
echo "Parent login success!";
echo "<script>location.href='internal/Parentindex.php'</script>";
break;
default:
$message = "Default Error occured!";
echo $message;
echo "<script>alert('$message');</script>";
echo "<script>location.href='index.php'</script>";
break;
}
} else {
$message = "Incorrect Password. Try Again!";
$location = "index.php";
echo "<script>alert('$message');</script>";
echo "<script>location.href = '$location';</script>";
echo $message;
}
} else {
$message = "Invalid Username or Account is Blocked/Rejected!";
$location = "index.php";
echo "<script>alert('$message');</script>";
echo "<script>location.href = '$location';</script>";
echo $message;
}
}
//-------------------------- Universal login code----XXXXXXXXXXXXXXXXXXX--------------------------------
?>