-
Notifications
You must be signed in to change notification settings - Fork 1
/
gradeServer.php
57 lines (49 loc) · 1.49 KB
/
gradeServer.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
<?php
session_start();
$stud_id = "";
$record_id = "";
$grade = "";
$id = 0;
$edit_state = false;
$db = mysqli_connect("localhost", "root", "", "experiment");
if (!$db) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
//insertion
if(isset($_POST['save'])){
$stud_id = $_POST['stud_id'];
$record_id = $_POST['record_id'];
$grade = $_POST['grade'];
$query = mysqli_query($db,
"INSERT INTO grade (stud_id, record_id, grade)
VALUES ('".$stud_id."', '".$record_id."', '".$grade."')");
$_SESSION['msg'] = "Grade established.";
if($query){
header("location:grade.php");
}else {
$_SESSION['msg'] = "Something went wrong.Please Check if the student or experiment exist.";
header("location:grade.php");
exit();
}
}
//update
if(isset($_POST['update'])){
$grade_id= $_POST['grade_id'];
$stud_id = $_POST['stud_id'];
$record_id = $_POST['record_id'];
$grade = $_POST['grade'];
mysqli_query($db, "UPDATE grade SET stud_id='".$stud_id."', record_id='".$record_id."' ,grade='".$grade."' WHERE grade_id='".$grade_id."'");
$_SESSION['msg'] = "Student Grade Updated!";
header('location:grade.php');
}
//delete
if(isset($_GET['del'])){
$grade_id= $_GET['del'];
mysqli_query($db, "DELETE FROM grade WHERE grade_id=".$grade_id);
$_SESSION['msg'] = "Student Grade Deleted!";
header('location:grade.php');
}
//read
$results = mysqli_query($db, "SELECT * FROM grade");
?>