getConnection(); if (!$pdo) { throw new Exception('Database connection failed'); } // Verifica se l'ID esiste $stmtCheck = $pdo->prepare("SELECT id FROM excel_templates WHERE id = ?"); $stmtCheck->execute([$id]); if ($stmtCheck->rowCount() === 0) { throw new Exception('Template not found'); } // Esegui l'eliminazione $stmt = $pdo->prepare("DELETE FROM excel_templates WHERE id = ?"); $stmt->execute([$id]); if ($stmt->rowCount() > 0) { $message = "Template deleted successfully!"; $status = "success"; } else { throw new Exception('Failed to delete template'); } } catch (Exception $e) { $message = $e->getMessage(); $status = "error"; } // Reindirizza con un messaggio header("Location: templates_dashboard.php?status=$status&message=" . urlencode($message)); exit;