-
Notifications
You must be signed in to change notification settings - Fork 0
/
crud.php
189 lines (178 loc) · 9.85 KB
/
crud.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
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "project480";
$conn = mysqli_connect($servername, $username, $password, $dbname);
if(!$conn){
die("Connection Failed: ". mysqli_connect_error());
}
//echo 'Connected successfully.<br>';
if(isset($_POST['insert_mark']))
{
$sql = "SELECT studentId FROM signup where studentId = '$_POST[studentId]'";
$result = mysqli_query($conn, $sql);
if (mysqli_num_rows($result) > 0) {
$sql = "SELECT studentId,courseId FROM marks where studentId = '$_POST[studentId]' AND courseId='$_POST[courseId]'";
$result = mysqli_query($conn, $sql);
if (mysqli_num_rows($result) > 0) echo "<script>alert('Already Exist.');</script>";
else{
$sql = "INSERT INTO marks (studentId, courseId, attendance, assignment, project, lab, quiz, mid1, mid2, final)
VALUES ('$_POST[studentId]','$_POST[courseId]','$_POST[attendance]','$_POST[assignment]','$_POST[project]','$_POST[lab]','$_POST[quiz]','$_POST[mid1]','$_POST[mid2]','$_POST[final]')";
if (mysqli_query($conn, $sql)) echo "<script>alert('Successfully Inserted.');</script>";
else echo "Error inserting value: " . mysqli_error($conn);
}
}
else echo "<script>alert('Id Not Found.');</script>";
include "admin.php";
}
if(isset($_POST['insert_grade']))
{
$sql = "SELECT studentId FROM signup where studentId = '$_POST[studentId]'";
$result = mysqli_query($conn, $sql);
if (mysqli_num_rows($result) > 0) {
$sql = "SELECT studentId,courseId,semester FROM gradesheet where studentId = '$_POST[studentId]' AND courseId='$_POST[courseId]'";
$result = mysqli_query($conn, $sql);
if (mysqli_num_rows($result) > 0) echo "<script>alert('Already Exist.');</script>";
else{
$sql = "INSERT INTO gradesheet (studentId, semester, courseId, credit, grade)
VALUES ('$_POST[studentId]','$_POST[semester]','$_POST[courseId]','$_POST[credit]','$_POST[grade]')";
if (mysqli_query($conn, $sql)) echo "<script>alert('Successfully Inserted.');</script>";
else echo "Error inserting value: " . mysqli_error($conn);
}
}
else echo "<script>alert('Id Not Found.');</script>";
include "admin.php";
}
if(isset($_POST['insert_gradepoint']))
{
$sql = "SELECT studentId FROM signup where studentId = '$_POST[studentId]'";
$result = mysqli_query($conn, $sql);
if (mysqli_num_rows($result) > 0) {
$sql = "SELECT studentId,semester FROM gradepoint where studentId = '$_POST[studentId]' AND semester='$_POST[semester]'";
$result = mysqli_query($conn, $sql);
if (mysqli_num_rows($result) > 0) echo "<script>alert('Already Exist.');</script>";
else{
$sql = "INSERT INTO gradepoint(studentId, semester, cgpa, gpa)
VALUES ('$_POST[studentId]','$_POST[semester]','$_POST[cgpa]','$_POST[gpa]')";
if (mysqli_query($conn, $sql)) echo "<script>alert('Successfully Inserted.');</script>";
else echo "Error inserting value: " . mysqli_error($conn);
}
}
else echo "<script>alert('Id Not Found.');</script>";
include "admin.php";
}
if(isset($_POST['update_mark'])){
if(!empty($_POST['attendance'])){
$sql = "UPDATE marks SET attendance='$_POST[attendance]' where studentId = '$_POST[studentId]' AND courseId='$_POST[courseId]'";
if (mysqli_query($conn, $sql)) echo "<script>alert('Successfully Updated.');</script>";
else echo "Error inserting value: " . mysqli_error($conn);
}
if(!empty($_POST['assignment'])){
$sql = "UPDATE marks SET assignment='$_POST[assignment]' where studentId = '$_POST[studentId]' AND courseId='$_POST[courseId]'";
if (mysqli_query($conn, $sql)) echo "<script>alert('Successfully Updated.');</script>";
else echo "Error inserting value: " . mysqli_error($conn);
}
if(!empty($_POST['project'])){
$sql = "UPDATE marks SET project='$_POST[project]' where studentId = '$_POST[studentId]' AND courseId='$_POST[courseId]'";
if (mysqli_query($conn, $sql)) echo "<script>alert('Successfully Updated.');</script>";
else echo "Error inserting value: " . mysqli_error($conn);
}
if(!empty($_POST['lab'])){
$sql = "UPDATE marks SET lab='$_POST[lab]' where studentId = '$_POST[studentId]' AND courseId='$_POST[courseId]'";
if (mysqli_query($conn, $sql)) echo "<script>alert('Successfully Updated.');</script>";
else echo "Error inserting value: " . mysqli_error($conn);
}
if(!empty($_POST['quiz'])){
$sql = "UPDATE marks SET quiz='$_POST[quiz]' where studentId = '$_POST[studentId]' AND courseId='$_POST[courseId]'";
if (mysqli_query($conn, $sql)) echo "<script>alert('Successfully Updated.');</script>";
else echo "Error inserting value: " . mysqli_error($conn);
}
if(!empty($_POST['mid1'])){
$sql = "UPDATE marks SET mid1='$_POST[mid1]' where studentId = '$_POST[studentId]' AND courseId='$_POST[courseId]'";
if (mysqli_query($conn, $sql)) echo "<script>alert('Successfully Updated.');</script>";
else echo "Error inserting value: " . mysqli_error($conn);
}
if(!empty($_POST['mid2'])){
$sql = "UPDATE marks SET mid2='$_POST[mid2]' where studentId = '$_POST[studentId]' AND courseId='$_POST[courseId]'";
if (mysqli_query($conn, $sql)) echo "<script>alert('Successfully Updated.');</script>";
else echo "Error inserting value: " . mysqli_error($conn);
}
if(!empty($_POST['final'])){
$sql = "UPDATE marks SET final='$_POST[final]' where studentId = '$_POST[studentId]' AND courseId='$_POST[courseId]'";
if (mysqli_query($conn, $sql)) echo "<script>alert('Successfully Updated.');</script>";
else echo "Error inserting value: " . mysqli_error($conn);
}
include "admin.php";
}
if(isset($_POST['update_grade'])){
if(!empty($_POST['semester'])){
$sql = "UPDATE gradesheet SET semester='$_POST[semester]' where studentId = '$_POST[studentId]' AND courseId='$_POST[courseId]'";
if (mysqli_query($conn, $sql)) echo "<script>alert('Successfully Updated.');</script>";
else echo "Error inserting value: " . mysqli_error($conn);
}
if(!empty($_POST['credit'])){
$sql = "UPDATE gradesheet SET credit='$_POST[credit]' where studentId = '$_POST[studentId]' AND courseId='$_POST[courseId]'";
if (mysqli_query($conn, $sql)) echo "<script>alert('Successfully Updated.');</script>";
else echo "Error inserting value: " . mysqli_error($conn);
}
if(!empty($_POST['grade'])){
$sql = "UPDATE gradesheet SET grade='$_POST[grade]' where studentId = '$_POST[studentId]' AND courseId='$_POST[courseId]'";
if (mysqli_query($conn, $sql)) echo "<script>alert('Successfully Updated.');</script>";
else echo "Error inserting value: " . mysqli_error($conn);
}
include "admin.php";
}
if(isset($_POST['update_gradepoint'])){
if(!empty($_POST['cgpa'])){
$sql = "UPDATE gradepoint SET cgpa='$_POST[cgpa]' where studentId = '$_POST[studentId]' AND semester='$_POST[semester]'";
if (mysqli_query($conn, $sql)) echo "<script>alert('Successfully Updated.');</script>";
else echo "Error inserting value: " . mysqli_error($conn);
}
if(!empty($_POST['gpa'])){
$sql = "UPDATE gradepoint SET gpa='$_POST[gpa]' where studentId = '$_POST[studentId]' AND semester='$_POST[semester]'";
if (mysqli_query($conn, $sql)) echo "<script>alert('Successfully Updated.');</script>";
else echo "Error inserting value: " . mysqli_error($conn);
}
include "admin.php";
}
if(isset($_POST['delete_mark'])){
if(!empty($_POST['studentId']) && !empty($_POST['courseId'])){
$sql = "SELECT studentId,courseId FROM marks where studentId = '$_POST[studentId]' AND courseId='$_POST[courseId]'";
$result = mysqli_query($conn, $sql);
if (mysqli_num_rows($result) > 0) {
$sql = "DELETE FROM marks where studentId = '$_POST[studentId]' AND courseId='$_POST[courseId]'";
if (mysqli_query($conn, $sql)) echo "<script>alert('Successfully Deleted.');</script>";
else echo "Error inserting value: " . mysqli_error($conn);
}
else echo "<script>alert('Not Found.');</script>";
}
include "admin.php";
}
if(isset($_POST['delete_grade'])){
if(!empty($_POST['studentId']) && !empty($_POST['courseId'])){
$sql = "SELECT studentId,courseId,semester FROM gradesheet where studentId = '$_POST[studentId]' AND courseId='$_POST[courseId]'";
$result = mysqli_query($conn, $sql);
if (mysqli_num_rows($result) > 0) {
$sql = "DELETE FROM gradesheet where studentId = '$_POST[studentId]' AND courseId='$_POST[courseId]'";
if (mysqli_query($conn, $sql)) echo "<script>alert('Successfully Deleted.');</script>";
else echo "Error inserting value: " . mysqli_error($conn);
}
else echo "<script>alert('Not Found.');</script>";
}
include "admin.php";
}
if(isset($_POST['delete_gradepoint'])){
if(!empty($_POST['studentId']) && !empty($_POST['semester'])){
$sql = "SELECT studentId,semester FROM gradepoint where studentId = '$_POST[studentId]' AND semester='$_POST[semester]'";
$result = mysqli_query($conn, $sql);
if (mysqli_num_rows($result) > 0) {
$sql = "DELETE FROM gradepoint where studentId = '$_POST[studentId]' AND semester='$_POST[semester]'";
if (mysqli_query($conn, $sql)) echo "<script>alert('Successfully Deleted.');</script>";
else echo "Error inserting value: " . mysqli_error($conn);
}
else echo "<script>alert('Not Found.');</script>";
}
include "admin.php";
}
mysqli_close($conn);