-
Notifications
You must be signed in to change notification settings - Fork 2
/
UPDATE_TT.php
82 lines (63 loc) · 2.14 KB
/
UPDATE_TT.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
<?php
include 'DB.php';
date_default_timezone_set('Asia/Kolkata');
function insertTT($conn) {
$sql = 'INSERT INTO `TIME_TABLE` (`DAY`, `TIME_SLOT`, `TEACHER_ID`, `SUBJECT`, `CLASSROOM`,`YEAR`,`DIVISION`,`BATCH`) VALUES
(\''.$_GET['DAY'].'\', \''.$_GET['TIME_SLOT'].'\', \''.$_GET['ID'].'\', \''.$_GET['SUBJECT'].'\', \''.$_GET['CLASSROOM'].'\', \''.$_GET['YEAR'].'\', \''.$_GET['DIVISION'].'\', \''.$_GET['BATCH'].'\')';
if ($conn->query($sql) === TRUE) {
echo "Time Table updated successfully";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
}
function updateTT($conn) {
$sql = 'UPDATE `TIME_TABLE` SET `SUBJECT`=\''.$_GET['SUBJECT'].'\' WHERE
`TIME_SLOT`=\''.$_GET['TIME_SLOT'].'\' AND `DAY`=\''.$_GET['DAY'].'\' AND `TEACHER_ID`=\''.$_GET['ID'].'\'';
if ($conn->query($sql) === TRUE) {
echo "Time Table updated successfully";
} else {
echo "Error updating Time Table: " . $conn->error;
}
}
function deleteTT($conn) {
$T1 = "";
$T2 = "";
if ($_GET['TIME_SLOT'] == "1-2"){
$T1 = "12:30-1:30";
$T2 = "1:30-2:30";
}elseif ($_GET['TIME_SLOT'] == "12:30-1:30") {
$T1 = "1-2";
$T2 = "12-1";
}elseif ($_GET['TIME_SLOT'] == "1:30-2:30") {
$T1 = "1-2";
$T2 = "2-3";
}elseif ($_GET['TIME_SLOT'] == "5-6") {
$T1 = "4:30-5:30";
$T2 = "5:30-6:30";
}
$sql = "DELETE FROM `TIME_TABLE` WHERE `TEACHER_ID`='".$_GET['ID']."' AND `TIME_SLOT` IN ('".$T1."','".$T2."')";
if ($conn->query($sql) === TRUE) {
} else {
}
}
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = 'SELECT * FROM `TEACHER` WHERE `ID` LIKE \''.$_GET['ID'].'\'';
$result = mysqli_query($conn, $sql);
if (mysqli_num_rows($result) > 0) {
deleteTT($conn);
$sql = 'SELECT * FROM `TIME_TABLE` WHERE
`TIME_SLOT`=\''.$_GET['TIME_SLOT'].'\' AND `DAY`=\''.$_GET['DAY'].'\' AND `TEACHER_ID`=\''.$_GET['ID'].'\'';
$result = mysqli_query($conn, $sql);
if (mysqli_num_rows($result) > 0) {
updateTT($conn);
} else {
insertTT($conn);
}
}
$conn->close();
?>