added pages
This commit is contained in:
@@ -1,22 +1,31 @@
|
||||
<?php
|
||||
include('include/headscript.php');
|
||||
include('../class/db-functions.php');
|
||||
|
||||
header('Content-Type: application/json');
|
||||
|
||||
try {
|
||||
if (!isset($_POST['nome']) || trim($_POST['nome']) === '') {
|
||||
throw new Exception("Nome matrice mancante.");
|
||||
}
|
||||
|
||||
$nome = trim($_POST['nome']);
|
||||
$db = DBHandlerSelect::getInstance();
|
||||
$pdo = $db->getConnection();
|
||||
|
||||
// Inserisci nuova matrice
|
||||
$stmt = $pdo->prepare("INSERT INTO matrice (nome) VALUES (:nome)");
|
||||
$stmt->bindParam(':nome', $nome, PDO::PARAM_STR);
|
||||
$stmt->execute();
|
||||
$id = $_POST['id'] ?? null;
|
||||
$nome = trim($_POST['nome'] ?? '');
|
||||
|
||||
echo json_encode(["success" => true]);
|
||||
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" => $e->getMessage()]);
|
||||
echo json_encode(['success' => false, 'message' => 'Errore: ' . $e->getMessage()]);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user