-
Notifications
You must be signed in to change notification settings - Fork 0
/
edit.php
203 lines (165 loc) · 5.95 KB
/
edit.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
<!DOCTYPE html>
<html lang="en">
<head>
<style>
body {
width: 100vw;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
font-family: sans-serif;
font-size: 16px;
background-color: #F0F8FF;
}
input{
width: 100%;
padding: 10px , 20px;
font-size: 1 rem;
margin: 15px 0;
box-sizing: border-box;
border: 3px solid salmon;
border-radius: 5px;
}
input[type="submit"]{
width: 100%;
padding: 20 px 20 px;
border: none;
background-color: red;
color: white;
padding: 10px;
cursor: pointer;
border-radius: 50px;
}
</style>
</head>
<?php
session_start();
$con = mysqli_connect('localhost','root','','COVID');
$nid = $_GET['id'];
if(isset($_POST['update1']))
{
$d = $_POST['bd'];
$sql = "update STUDENT_INFO set BIRTH_DATE = '$d' where NID like '$nid'";
$result = mysqli_query($con, $sql);
echo "Success\n";
}
if(isset($_POST['update2']))
{
$name = $_POST['name'];
$sql = "select NAME from STUDENT_INFO where NID like '$nid'";
$result = mysqli_query($con, $sql);
$name1 = mysqli_fetch_array($result);
$sql = "update STUDENT_INFO set NAME = '$name' where NID like '$nid'";
$result = mysqli_query($con, $sql);
$sql = "update LOGIN set USERNAME = '$name' where USERNAME like '$name1[0]'";
$result = mysqli_query($con, $sql);
echo "Success\n";
}
if(isset($_POST['update3']))
{
$ni = $_POST['nid'];
$sql = "select * from STUDENT_INFO where NID like '$ni'";
$result = mysqli_query($con, $sql);
$row = mysqli_num_rows($result);
if($row == 0){
$sql = "select NAME from STUDENT_INFO where NID like '$nid'";
$result = mysqli_query($con, $sql);
$na = mysqli_fetch_array($result);
$sql = "update STUDENT_INFO set NID = '$ni' where NAME like '$na[0]'";
$result = mysqli_query($con, $sql);
$nid = $ni;
echo "Success\n";
}else{
echo "this id exists";
}
}
if(isset($_POST['update4'])){
$honame = $_POST['Hos_name'];
$sql = "select 1ST_D,2ND_D,HOS_NAME from STUDENT_INFO where NID like '$nid'";
$result = mysqli_query($con,$sql);
$da = mysqli_fetch_array($result); // CURRENT HOSPITAL'S DETAILS
$sql = "select CAPACITY from HOSPITAL_INFO where NAME like '$honame'";
$result = mysqli_query($con,$sql);
$caphos = mysqli_fetch_array($result); //SELECTED HOSPITAL'S CAPACITY
$sql = "select FILLED from DATE where 1ST_DOSE like '$da[0]' AND 2ND_DOSE like '$da[1]' AND NAME like '$honame'";
$result = mysqli_query($con,$sql);
$cur_cap = mysqli_fetch_array($result); // FILLED ON THE CURRENT DATE
if(is_null($cur_cap)){
$cur_cap = 0;
}
if($cur_cap == $caphos){
echo "select a new one\n";
header("refresh:1;url= edit.php");
}else{
if($cur_cap == 0){
$cur_cap = 1;
$sql = "insert into DATE values('$da[0]','$da[1]','$honame','$cur_cap')";
$result = mysqli_query($con,$sql);
$sql = "select VACCINE from HOSPITAL_INFO where NAME like '$honame'";
$result = mysqli_query($con,$sql);
$vac = mysqli_fetch_array($result);
$sql = "update STUDENT_INFO set HOS_NAME = '$honame', VACCINE = '$vac[0]' where NID like '$nid'";
$result = mysqli_query($con,$sql);
$sql = "select FILLED from DATE where 1ST_DOSE like '$da[0]' AND 2ND_DOSE like '$da[1]' AND NAME like '$da[2]'";
$result = mysqli_query($con,$sql);
$cc = mysqli_fetch_array($result);
$cc[0] -= 1;
$sql = "update DATE set FILLED = '$cc[0]' where 1ST_DOSE like '$da[0]' AND 2ND_DOSE like '$da[1]' AND NAME like '$da[2]'";
$result = mysqli_query($con,$sql);
}else{
$cur_cap[0]++;
$sql = "update DATE set FILLED = '$cur_cap[0]' where 1ST_DOSE like '$da[0]' AND 2ND_DOSE like '$da[1]' AND NAME like '$honame'";
$result = mysqli_query($con,$sql);
$sql = "select VACCINE from HOSPITAL_INFO where NAME like '$honame'";
$result = mysqli_query($con,$sql);
$vac = mysqli_fetch_array($result);
$sql = "update STUDENT_INFO set HOS_NAME = '$honame', VACCINE = '$vac[0]' where NID like '$nid'";
$result = mysqli_query($con,$sql);
$sql = "select FILLED from DATE where 1ST_DOSE like '$da[0]' AND 2ND_DOSE like '$da[1]' AND NAME like '$da[2]'";
$result = mysqli_query($con,$sql);
$cc = mysqli_fetch_array($result);
$cc[0] -= 1;
$sql = "update DATE set FILLED = '$cc[0]' where 1ST_DOSE like '$da[0]' AND 2ND_DOSE like '$da[1]' AND NAME like '$da[2]'";
$result = mysqli_query($con,$sql);
}
}
}
if(isset($_POST['Log Out'])){
session_destroy();
header("refresh:1;url=Home.php");
}
?>
<h3>Update Data</h3>
<form method="POST">
<label>Name : </label>
<input type = "text" name = "name" value = ""/>
<input type="submit" name="update2" value="Update">
<br>
<label>NID : </label>
<input type = "text" name = "nid" value = ""/>
<input type="submit" name="update3" value="Update">
<br>
<label>Birth date:</label>
<input type="text" name="bd" value="YEAR-MONTH-DAY">
<input type="submit" name="update1" value="Update">
<br>
<label>Hospital Name:</label>
<select name="Hos_name" required/>
<option >Hospital Names</option>
<?php
$con = mysqli_connect('localhost','root','','COVID');
$sql = "select name from HOSPITAL_INFO";
$result = mysqli_query($con, $sql);
$row = mysqli_num_rows($result);
while ($row = mysqli_fetch_array($result)){
echo "<option value='". $row[0] ."'>" .$row[0] ."</option>" ;
}
?>
</select>
<input type="submit" name="update4" value="Update">
<br>
</form>
<form action="Home.php" method="POST">
<input style="margin: 7px;width:430px" type="submit" name="Log Out" value="Log Out">
</form>