-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheditteacher.php
More file actions
47 lines (39 loc) · 1.32 KB
/
Copy patheditteacher.php
File metadata and controls
47 lines (39 loc) · 1.32 KB
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
<?php
include 'config.php';
$firstname = $_POST["teacherFirstNameedit"];
$lastname = $_POST["teacherLastNameedit"];
$email = $_POST["teacherEmailedit"];
$age = $_POST["teacherAgeedit"];
$num = $_POST["teacherNumedit"];
$mat = $_POST["teacherMatriculeedit"];
$group_idsedit = $_POST["group_idsedit"];
// Update teacher details
$sql = "UPDATE teachers SET firstname = ?, lastname = ?, email = ?, age = ?, num = ? WHERE matricule = ?";
$stmt = $conn->prepare($sql);
$stmt->bind_param("ssssis", $firstname, $lastname, $email, $age, $num, $mat);
$stmt->execute();
// Get the teacher's ID
$sql = "SELECT id FROM teachers WHERE matricule = ?";
$stmt = $conn->prepare($sql);
$stmt->bind_param("s", $mat);
$stmt->execute();
$result = $stmt->get_result();
$row = $result->fetch_assoc();
$teacher_id = $row['id'];
// Delete the current group assignments for the teacher
$sql = "DELETE FROM teacher_groups WHERE teacher_id = ?";
$stmt = $conn->prepare($sql);
$stmt->bind_param("i", $teacher_id);
$stmt->execute();
// Insert the new group assignments
foreach ($group_idsedit as $group_id) {
$sql = "INSERT INTO teacher_groups (teacher_id, group_id) VALUES (?, ?)";
$stmt = $conn->prepare($sql);
$stmt->bind_param("ii", $teacher_id, $group_id);
$stmt->execute();
}
$stmt->close();
$conn->close();
header('Location: teachers.php');
die();
?>