diff --git a/htdocs/admin/subjects.php b/htdocs/admin/subjects.php index 22e4b68..b2e4205 100644 --- a/htdocs/admin/subjects.php +++ b/htdocs/admin/subjects.php @@ -3,20 +3,47 @@ session_start(); if (!isset($_SESSION['admin'])) { header("Location: login.php"); exit; } include("../lib/db.php"); -if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST['name'])) { +// FIX: Usa prepared statements per sicurezza +if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST['name']) && !isset($_POST['update'])) { $name = $_POST['name']; $teacher = $_POST['teacher']; $room = $_POST['room']; - if (!empty($name)) { - $conn->query("INSERT INTO subjects (name,teacher,room) VALUES ('$name','$teacher','$room')"); + + if (!empty($name)) { + $stmt = $conn->prepare("INSERT INTO subjects (name, teacher, room) VALUES (?, ?, ?)"); + $stmt->bind_param("sss", $name, $teacher, $room); + $stmt->execute(); + $stmt->close(); } - header("Location: subjects.php"); exit; + header("Location: subjects.php"); + exit; } +// FIX: Aggiunto redirect dopo update +if(isset($_POST['update'])){ + $id = intval($_POST['id']); + $name = $_POST['name']; + $teacher = $_POST['teacher']; + $room = $_POST['room']; + + $stmt = $conn->prepare("UPDATE subjects SET name=?, teacher=?, room=? WHERE id=?"); + $stmt->bind_param("sssi", $name, $teacher, $room, $id); + $stmt->execute(); + $stmt->close(); + + header("Location: subjects.php"); + exit; +} + +// FIX: Usa prepared statement anche per delete if (isset($_GET['delete'])) { $id = intval($_GET['delete']); - $conn->query("DELETE FROM subjects WHERE id=$id"); - header("Location: subjects.php"); exit; + $stmt = $conn->prepare("DELETE FROM subjects WHERE id=?"); + $stmt->bind_param("i", $id); + $stmt->execute(); + $stmt->close(); + header("Location: subjects.php"); + exit; } ?> @@ -41,50 +68,50 @@ if (isset($_GET['delete'])) {
| ID | @@ -98,12 +125,12 @@ if(isset($_GET['edit'])){ while($row=$res->fetch_assoc()){ echo "|||||||
|---|---|---|---|---|---|---|---|
| {$row['id']} | -{$row['name']} | -{$row['teacher']} | -{$row['room']} | +" . htmlspecialchars($row['name']) . " | +" . htmlspecialchars($row['teacher']) . " | +" . htmlspecialchars($row['room']) . " | Modifica | - Elimina + Elimina |
| $d"; ?> @@ -59,10 +64,12 @@ if ($res->num_rows === 0) { WHERE subjects.teacher='$teacher' AND timetable.day='$d' AND timetable.hour=$hnum"); if($row = $q->fetch_assoc()){ echo " |
- {$row['name']}
- {$row['class_name']}
- {$row['room']}
- | ";
+ "; } @@ -71,6 +78,41 @@ if ($res->num_rows === 0) { } ?> |
|---|
Copyright (C) 2025 EmmeV. - Released under GNU AGPL 3.0 License.