Repository navigation
Expand file tree
/
Copy pathsolus_enterProInfo.php
More file actions
107 lines (96 loc) · 3.54 KB
/
Copy pathsolus_enterProInfo.php
File metadata and controls
107 lines (96 loc) · 3.54 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
100
101
102
103
104
105
106
107
<!-- // Purpose: To enter a new program or edit an existing program
// Author: Songyu Yang -->
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Student Management System</title>
<link rel="stylesheet" type = "text/css" href="main.css">
<link rel="stylesheet" type = "text/css" href="Table_CSS.css">
</head>
<body>
<?php
// Include the database connection file
include 'solus_connectdb.php';
// Get the values of the input fields
$type = isset($_POST["type"]) ? $_POST["type"] : 0;
$code = $_POST["code"];
$name = $_POST["name"];
$automaticAcceptanceGPA = $_POST["automaticAcceptanceGPA"];
$pendingListAcceptanceGPA = $_POST["pendingListAcceptanceGPA"];
$time = time();
// Validate the input fields
$errors = array();
if (empty($code)) {
$errors[] = "Please enter a degree plan code.";
}
if (empty($name)) {
$errors[] = "Please enter a degree plan name.";
}
if (empty($automaticAcceptanceGPA)) {
$errors[] = "Please enter the automatic acceptance GPA.";
}
if (!is_numeric($automaticAcceptanceGPA)) {
$errors[] = "Automatic acceptance GPA must be a number.";
}
if (empty($pendingListAcceptanceGPA)) {
$errors[] = "Please enter the pending list acceptance GPA.";
}
if (!is_numeric($pendingListAcceptanceGPA)) {
$errors[] = "Pending list acceptance GPA must be a number.";
}
// If there are errors, display them
if (!empty($errors)) {
echo "<h2>Errors:</h2>";
echo "<ul>";
foreach ($errors as $error) {
echo "<li>$error</li>";
}
// Go back to the previous page
echo "</ul>";
echo '<button onclick="goBack()">Go Back</button>';
echo '<script>function goBack() {window.history.back();}</script>';
} else {
if (!$type) {
// Insert the values into the database
$sql = "INSERT INTO degreePlan (`code`, `name`, `automaticAcceptanceGPA`, `pendingListAcceptanceGPA`)
VALUES (:code, :name, :automaticAcceptanceGPA, :pendingListAcceptanceGPA)";
$stmt = $connection->prepare($sql);
$stmt->execute([
'code' => $code,
'name' => $name,
'automaticAcceptanceGPA' => $automaticAcceptanceGPA,
'pendingListAcceptanceGPA' => $pendingListAcceptanceGPA
]);
// If the insert was successful, display a success message
if ($stmt->rowCount()) {
echo "<script type='text/javascript'>alert('Your Program was added!');location.href='solus_listPro.php';</script>";
return;
} else {
echo "<script type='text/javascript'>alert('fail added!');location.href='solus_enterPro.php';</script>";
return;
}
} else {
// Update the values into the database
$sql = "update degreePlan set `name`=:name, automaticAcceptanceGPA=:automaticAcceptanceGPA,
pendingListAcceptanceGPA=:pendingListAcceptanceGPA where code = :code";
$stmt = $connection->prepare($sql);
$stmt->execute([
'code' => $code,
'name' => $name,
'automaticAcceptanceGPA' => $automaticAcceptanceGPA,
'pendingListAcceptanceGPA' => $pendingListAcceptanceGPA
]);
if ($stmt->rowCount()) {
// If the update was successful, display a success message
echo "<script type='text/javascript'>alert('Your Program was edited!');location.href='solus_listPro.php';</script>";
return;
} else {
echo "<script type='text/javascript'>alert('fail edited!');location.href='solus_listPro.php';</script>";
return;
}
}
}
?>
</body>
</html>