TRF Certest first commit
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
// Abilita la gestione degli errori
|
||||
ini_set('display_errors', 1);
|
||||
error_reporting(E_ALL);
|
||||
|
||||
// Includi la connessione al database
|
||||
require_once 'class/db-functions.php';
|
||||
|
||||
try {
|
||||
// Controlla se è stato passato un ID valido
|
||||
if (!isset($_GET['id']) || !is_numeric($_GET['id'])) {
|
||||
throw new Exception('Invalid ID');
|
||||
}
|
||||
|
||||
$id = intval($_GET['id']); // Sanifica l'ID
|
||||
|
||||
// Connessione al database
|
||||
$db = DBHandlerSelect::getInstance();
|
||||
$pdo = $db->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: xlstemplates_grid.php?status=$status&message=" . urlencode($message));
|
||||
exit;
|
||||
Reference in New Issue
Block a user