-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadd_results.php
141 lines (127 loc) · 5.56 KB
/
add_results.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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
<!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 href="https://fonts.googleapis.com/css?family=Roboto" rel="stylesheet">
<link rel="stylesheet" href="./css/font-awesome-4.7.0/css/font-awesome.css">
<link rel="stylesheet" href="./css/form.css">
<title>Dashboard</title>
</head>
<body>
<div class="title">
<a href="dashboard.php"><img src="./images/logo1.png" alt="" class="logo"></a>
<span class="heading">Dashboard</span>
<a href="logout.php" style="color: white"><span class="fa fa-sign-out fa-2x">Logout</span></a>
</div>
<div class="nav">
<ul>
<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>Enter Marks</legend>
<?php
include("init.php");
include("session.php");
$select_class_query="SELECT `name` from `class`";
$class_result=mysqli_query($conn,$select_class_query);
//select 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="text" name="rno" placeholder="Roll No">
<input type="text" name="p1" id="" placeholder="Paper 1">
<input type="text" name="p2" id="" placeholder="Paper 2">
<input type="text" name="p3" id="" placeholder="Paper 3">
<input type="text" name="p4" id="" placeholder="Paper 4">
<input type="text" name="p5" id="" placeholder="Paper 5">
<input type="submit" value="Submit">
</fieldset>
</form>
</div>
</body>
</html>
<?php
if(isset($_POST['rno'],$_POST['p1'],$_POST['p2'],$_POST['p3'],$_POST['p4'],$_POST['p5']))
{
$rno=$_POST['rno'];
if(!isset($_POST['class_name']))
$class_name=null;
else
$class_name=$_POST['class_name'];
$p1=(int)$_POST['p1'];
$p2=(int)$_POST['p2'];
$p3=(int)$_POST['p3'];
$p4=(int)$_POST['p4'];
$p5=(int)$_POST['p5'];
$marks=$p1+$p2+$p3+$p4+$p5;
$percentage=$marks/5;
// validation
if (empty($class_name) or empty($rno) or $p1>100 or $p2>100 or $p3>100 or $p4>100 or $p5>100 or $p1<0 or $p2<0 or $p3<0 or $p4<0 or $p5<0 ) {
if(empty($class_name))
echo '<p class="error">Please select class</p>';
if(empty($rno))
echo '<p class="error">Please enter roll number</p>';
if(preg_match("/[a-z]/i",$rno))
echo '<p class="error">Please enter valid roll number</p>';
if(preg_match("/[a-z]/i",$marks))
echo '<p class="error">Please enter valid marks</p>';
if($p1>100 or $p2>100 or $p3>100 or $p4>100 or $p5>100 or $p1<0 or $p2<0 or $p3<0 or $p4<0 or $p5<0)
echo '<p class="error">Please enter valid marks</p>';
exit();
}
$name=mysqli_query($conn,"SELECT `name` FROM `students` WHERE `rno`='$rno' and `class_name`='$class_name'");
while($row = mysqli_fetch_array($name)) {
$display=$row['name'];
echo $display;
}
$sql="INSERT INTO `result` (`name`, `rno`, `class`, `p1`, `p2`, `p3`, `p4`, `p5`, `marks`, `percentage`) VALUES ('$display', '$rno', '$class_name', '$p1', '$p2', '$p3', '$p4', '$p5', '$marks', '$percentage')";
$sql=mysqli_query($conn,$sql);
if (!$sql) {
echo '<script language="javascript">';
echo 'alert("Invalid Details")';
echo '</script>';
}
else{
echo '<script language="javascript">';
echo 'alert("Successful")';
echo '</script>';
}
}
?>