-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstudent_registration_backend.php
106 lines (77 loc) · 3.96 KB
/
student_registration_backend.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
<?php
session_start();
$con = mysqli_connect('localhost','root','','COVID');
if(isset($_POST['login'])){
// variable
$reg_name = $_POST['reg_name'];
$NID = $_POST['nid'];
$reg_pass = $_POST['reg_pwd'];
$insname = $_POST['ins'];
$ho_name = $_POST['Hos_name'];
$tomorrowDate = date("Y-m-d",strtotime("+1 day")); // getting tomorrow date
$tomorrow4week = date("Y-m-d",strtotime("+4 week")); // getting date after 28 days
//checking if the hospital is filled or not
$sql = "select FILLED from DATE where 1st_dose = '$tomorrowDate' AND NAME like '$ho_name%'";
$result = mysqli_query($con, $sql);
$row = mysqli_fetch_array($result);
if(is_null($row[0])){
$row[0] = 0;
}$x = $row[0] + 1;
$sql = "select CAPACITY from HOSPITAL_INFO where NAME like '$ho_name'";
$result = mysqli_query($con, $sql);
$row2 = mysqli_fetch_array($result);
if($row[0] == $row2[0]){
echo "Sorry this hospital is filled. Please try a new hospital\n";
header("refresh:2;url=student_registration.php");
}else{
//checking if the user is already registered or not
$sql = "select * from LOGIN where USERNAME like '$reg_name'";
$result = mysqli_query($con, $sql);
$row = mysqli_num_rows($result);
if($row >= 1){
echo "This user has already registered.\n";
header("refresh:2;url=student_registration.php");
}
else{
//checking the infos
$sql = "select * from STUDENT_INFO where NAME like '$reg_name' AND NID like '$NID' ";
$result = mysqli_query($con, $sql);
$row = mysqli_num_rows($result);
if($row >= 1){
$_SESSION['rname'] = $reg_name;
echo 'login Successful';
//inserting username and pass to login table
$sql = "insert into LOGIN (USERNAME,PASSWORD) values ('" .$reg_name."','".$reg_pass."')";
$result = mysqli_query($con,$sql);
//updating the vaccine name for student
$sql = "select VACCINE from HOSPITAL_INFO where NAME like '$ho_name'" ;
$result = mysqli_query($con,$sql);
$row = mysqli_fetch_array($result);
$sql = "update STUDENT_INFO set REGISTRATION = 'DONE', HOS_NAME = '$ho_name',1ST_D = '$tomorrowDate' , 2ND_D = '$tomorrow4week', VACCINE = '$row[0]' where NID like '$NID'";
$result = mysqli_query($con,$sql);
//updating the filled column of the hospital
$sql = "select FILLED from DATE where 1st_dose = '$tomorrowDate' AND NAME like '$ho_name%'";
$result = mysqli_query($con, $sql);
$row = mysqli_fetch_array($result);
if(is_null($row[0])){
$row[0] = 0;
}
if($row[0] == 0){
//if no user is registered on that date
$sql = "insert into DATE values ('".$tomorrowDate."','".$tomorrow4week."','".$ho_name."', '".$x."')";
$result = mysqli_query($con,$sql);
header("refresh:1;url=login.php");
}else{
//atleast one user is registered on that date
$sql = "update DATE set FILLED = ".$x." where 1st_dose = '$tomorrowDate' AND NAME like '$ho_name%'";
$result = mysqli_query($con,$sql);
header("refresh:1;url=login.php");
}
}else{
echo "NOT SUCCESSFULL";
header("refresh:2;url=student_registration.php");
}
}
}
}
?>