32 lines
994 B
PHP
32 lines
994 B
PHP
<?php
|
|
include('../class/db-functions.php');
|
|
|
|
header('Content-Type: application/json');
|
|
|
|
try {
|
|
$db = DBHandlerSelect::getInstance();
|
|
$pdo = $db->getConnection();
|
|
|
|
$id = $_POST['id'] ?? null;
|
|
$nome = trim($_POST['nome'] ?? '');
|
|
|
|
if ($nome === '') {
|
|
echo json_encode(['success' => false, 'message' => 'Il nome della matrice è obbligatorio.']);
|
|
exit;
|
|
}
|
|
|
|
if ($id) {
|
|
// Aggiornamento
|
|
$stmt = $pdo->prepare("UPDATE matrice SET nome = ? WHERE id = ?");
|
|
$stmt->execute([$nome, $id]);
|
|
echo json_encode(['success' => true, 'message' => 'Matrice aggiornata con successo.']);
|
|
} else {
|
|
// Inserimento
|
|
$stmt = $pdo->prepare("INSERT INTO matrice (nome) VALUES (?)");
|
|
$stmt->execute([$nome]);
|
|
echo json_encode(['success' => true, 'message' => 'Matrice creata con successo.']);
|
|
}
|
|
} catch (Exception $e) {
|
|
echo json_encode(['success' => false, 'message' => 'Errore: ' . $e->getMessage()]);
|
|
}
|