= $max_score) { $_SESSION['error_message'] = 'Min score must be less than max score.'; header('Location: school_settings.php'); exit; } try { $pdo = db(); $sql = "UPDATE grading_scales SET grade_name = ?, min_score = ?, max_score = ? WHERE id = ?"; $stmt = $pdo->prepare($sql); $stmt->execute([$grade_name, $min_score, $max_score, $id]); $_SESSION['success_message'] = 'Grade updated successfully.'; } catch (PDOException $e) { if ($e->errorInfo[1] == 1062) { // Duplicate entry $_SESSION['error_message'] = "A grade with that name already exists in this section."; } else { $_SESSION['error_message'] = 'Database error: ' . $e->getMessage(); } } } header('Location: school_settings.php'); exit;