-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathremove_takes.php
More file actions
100 lines (72 loc) · 2.14 KB
/
remove_takes.php
File metadata and controls
100 lines (72 loc) · 2.14 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="description" content="">
<meta name="author" content="">
<title>Registration Confirmation</title>
<?php include("components/header.php"); ?>
</head>
<?php
include('database.php');
$user;
$crn;
$message = "";
if (!empty($_POST["user"])) {
$user = $_POST["user"];
} else {
$user = $_COOKIE['validated'];
}
if (!empty($_POST["crn"])) {
$crn = $_POST["crn"];
} else {
$crn = 'crn';
}
$stmt = 'SELECT * FROM Takes WHERE ID=' . $user . ' AND CRN= ' . $crn ; // ON DUPLICATE KEY UPDATE ;
$stmt2 = 'DELETE FROM Takes WHERE ID=' . $user . ' AND CRN= ' . $crn ; // ON DUPLICATE KEY UPDATE ;
$stmt3 = 'UPDATE CLASS SET current_enrollment = current_enrollment - 1 WHERE CRN = ' . $crn;
$result = $conn->query($stmt);
if (mysqli_num_rows($result) === 0) {
$message = "Not registered for this class";
}
else{
$success = true;
try{
$conn->query("BEGIN TRANSACTION");
$val1 = $conn->query($stmt2);
$val2 = $conn->query($stmt3);
$conn->commit();
$success = $success && $val1 && $val2;
if($success){
$message = "You've successfully unenrolled";
}else {
$message = "Error: " . $stmt . "<br>" . $conn->error;
}
}catch(Exception $e){
$conn->rollBack();
$message = "Error: " . $stmt . "<br>" . $conn->error;
}
}
?>
<body id="page-top">
<?php include("components/navbar.php"); ?>
<div id="wrapper">
<?php include("components/sidebar.php"); ?>
<div id="content-wrapper">
<div class="container-fluid">
<!-- Page Content -->
<h3>Registration </h3>
</br>
<p><?php echo $message ?></p>
</div>
<!-- /.container-fluid -->
<?php include("components/footer.php"); ?>
</div>
<!-- /.content-wrapper -->
</div>
<!-- /#wrapper -->
<?php include("components/javascript.php"); ?>
</body>
</html>