-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadd_subject.php
85 lines (78 loc) · 2.79 KB
/
add_subject.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
<?php include 'db.php';
session_start();
// Check if the user is logged in
if (!isset($_SESSION['username'])) {
header("Location: login.php"); // Redirect to login page if not logged in
exit();
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Add Subject</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css" rel="stylesheet">
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css" rel="stylesheet">
<style>
body {
display: flex;
}
.sidebar {
min-width: 250px;
background-color: #f8f9fa;
height: 100vh;
padding: 15px;
}
.sidebar a {
display: block;
padding: 10px;
text-decoration: none;
color: #000;
}
.sidebar a:hover {
background-color: #ddd;
}
.content {
flex-grow: 1;
padding: 20px;
}
</style>
</head>
<body>
<div class="sidebar">
<h4><b>Navigation</b></h4>
<a href="index.php">Home</a>
<a href="add_attendance.php">Add Attendance</a>
<a href="view_attendance.php">View Attendance</a>
<a href="add_marks.php">Add Marks</a>
<a href="view_marks.php">View Marks</a>
<a href="add_student.php">Add Student</a>
<a href="view_students.php">View Students</a>
<a href="add_subject.php">Add Subject</a>
<a href="view_subjects.php">View Subjects</a>
<a href="logout.php" class="nav-link" style="color: black;"><i class="fas fa-sign-out-alt"></i> Logout</a>
</div>
<div class="content">
<h2>Add Subject</h2>
<form action="add_subject.php" method="POST">
<div class="mb-3">
<label for="subject_name" class="form-label">Subject Name</label>
<input type="text" class="form-control" id="subject_name" name="subject_name" required>
</div>
<button type="submit" class="btn btn-primary">Add Subject</button>
</form>
<?php
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$subject_name = $_POST['subject_name'];
$sql = "INSERT INTO subjects (subject_name) VALUES ('$subject_name')";
if ($conn->query($sql) === TRUE) {
echo "<div class='alert alert-success'>Subject added successfully.</div>";
} else {
echo "<div class='alert alert-danger'>Error: " . $sql . "<br>" . $conn->error . "</div>";
}
}
?>
</div>
</body>
</html>