-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadd_classes.php
106 lines (95 loc) · 3.77 KB
/
add_classes.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<link rel="stylesheet" href="./css/home.css">
<link rel="stylesheet" href="./css/form.css">
<link href="https://fonts.googleapis.com/css?family=Roboto" rel="stylesheet">
<link rel="stylesheet" href="https://pro.fontawesome.com/releases/v5.10.0/css/all.css" integrity="sha384-AYmEC3Yw5cVb3ZcuHtOA93w35dYTsvhLPVnYs9eStHfGJvOvKxVfELGroGkvsg+p" crossorigin="anonymous"/>
<title>SSRMS</title>
</head>
<body>
<div class="title">
<a href="dashboard.php"><img src="./images/logo1.png" alt="" class="logo"></a>
<span class="heading">Class Section</span>
<a href="logout.php" style="color: white; text-decoration:none;"><span class="fa fa-sign-out"></span> Logout</a>
</div>
<div class="nav">
<ul>
<li>
<a href="dashboard.php">Dashboard</a>
</li>
<li class="dropdown" onclick="toggleDisplay('1')">
<a href="" class="dropbtn">Classes  
<span class="fa fa-angle-down"></span>
</a>
<div class="dropdown-content" id="1">
<a href="add_classes.php">Add Class</a>
<a href="manage_classes.php">Manage Class</a>
</div>
</li>
<li class="dropdown" onclick="toggleDisplay('2')">
<a href="#" class="dropbtn">Students  
<span class="fa fa-angle-down"></span>
</a>
<div class="dropdown-content" id="2">
<a href="add_students.php">Add Students</a>
<a href="manage_students.php">Manage Students</a>
</div>
</li>
<li class="dropdown" onclick="toggleDisplay('3')">
<a href="#" class="dropbtn">Results  
<span class="fa fa-angle-down"></span>
</a>
<div class="dropdown-content" id="3">
<a href="add_results.php">Add Results</a>
<a href="manage_results.php">Manage Results</a>
</div>
</li>
</ul>
</div>
<div class="main">
<form action="" method="post">
<fieldset>
<legend>Add Class</legend>
<input type="text" name="class_name" placeholder="Class Name">
<input type="text" name="class_id" placeholder="Class ID">
<input type="submit" value="Submit">
</fieldset>
</form>
</div>
<div class="footer">
</div>
</body>
</html>
<?php
include('init.php');
include('session.php');
if (isset($_POST['class_name'],$_POST['class_id'])) {
$name=$_POST["class_name"];
$id=$_POST["class_id"];
// validation
if (empty($name) or empty($id) or preg_match("/[a-z]/i",$id)) {
if(empty($name))
echo '<p class="error">Please enter class</p>';
if(empty($id))
echo '<p class="error">Please enter class id</p>';
if(preg_match("/[a-z]/i",$id))
echo '<p class="error">Please enter valid class id</p>';
exit();
}
$sql = "INSERT INTO `class` (`name`, `id`) VALUES ('$name', '$id')";
$result=mysqli_query($conn,$sql);
if (!$result) {
echo '<script language="javascript">';
echo 'alert("Invalid class name or class id")';
echo '</script>';
} else{
echo '<script language="javascript">';
echo 'alert("Success!!")';
echo '</script>';
}
}
?>