-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadd_students.php
127 lines (115 loc) · 4.87 KB
/
add_students.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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
<!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" type="text/css" href="./css/form.css" media="all">
<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">Students 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 Student</legend>
<input type="text" name="student_name" placeholder="Student Name">
<input type="text" name="roll_no" placeholder="Roll No">
<?php
include('init.php');
include('session.php');
$class_result=mysqli_query($conn,"SELECT `name` FROM `class`");
echo '<select name="class_name">';
echo '<option selected disabled>Select Class</option>';
while($row = mysqli_fetch_array($class_result)){
$display=$row['name'];
echo '<option value="'.$display.'">'.$display.'</option>';
}
echo'</select>'
?>
<input type="submit" value="Submit">
</fieldset>
</form>
</div>
<div class="footer">
</div>
</body>
</html>
<?php
if(isset($_POST['student_name'],$_POST['roll_no'])) {
$name=$_POST['student_name'];
$rno=$_POST['roll_no'];
if(!isset($_POST['class_name']))
$class_name=null;
else
$class_name=$_POST['class_name'];
// validation
if (empty($name) or empty($rno) or empty($class_name) or preg_match("/[a-z]/i",$rno) or !preg_match("/^[a-zA-Z ]*$/",$name)) {
if(empty($name))
echo '<p class="error">Please enter name</p>';
if(empty($class_name))
echo '<p class="error">Please select your class</p>';
if(empty($rno))
echo '<p class="error">Please enter your roll number</p>';
if(preg_match("/[a-z]/i",$rno))
echo '<p class="error">Please enter valid roll number</p>';
if (!preg_match("/^[a-zA-Z ]*$/",$name)) {
echo '<p class="error">No numbers or symbols allowed in name</p>';
}
exit();
}
$sql = "INSERT INTO `students` (`name`, `rno`, `class_name`) VALUES ('$name', '$rno', '$class_name')";
$result=mysqli_query($conn,$sql);
if (!$result) {
echo '<script language="javascript">';
echo 'alert("Invalid Details")';
echo '</script>';
}
else{
echo '<script language="javascript">';
echo 'alert("Success!!")';
echo '</script>';
}
}
?>