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