-
Notifications
You must be signed in to change notification settings - Fork 1
/
updateGrades.php
29 lines (22 loc) · 889 Bytes
/
updateGrades.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
<?php
include "connectToDB.php";
foreach ($_POST as $key => $value) {
$studentId = substr($key,6);
echo $studentId;
$sql = "SELECT * FROM grade WHERE assignmentName = ? AND studentId = ?;";
$stmt= $pdo->prepare($sql);
$stmt->execute([$_COOKIE['assignment'], $studentId]);
$data = $stmt->fetchAll();
if(count($data) === 0){
$sql = "INSERT INTO grade (assignmentName, score,studentId,teacherId) VALUES (?,?,?,?);";
$stmt= $pdo->prepare($sql);
$stmt->execute([$_COOKIE['assignment'], $value, (int)$studentId, $_COOKIE['id']]);
}
else{
$sql = "UPDATE grade SET score = ? WHERE assignmentName = ? AND studentId = ? AND teacherId = ?;";
$stmt= $pdo->prepare($sql);
$stmt->execute([$value, $_COOKIE['assignment'], (int)$studentId, $_COOKIE['id']]);
}
}
header("Location: teacherMainPage.php");
?>