update mescole and photo diagram
This commit is contained in:
@@ -1,31 +1,28 @@
|
||||
<?php
|
||||
include('../class/db-functions.php');
|
||||
require_once("include/headscript.php");
|
||||
$db = DBHandlerSelect::getInstance();
|
||||
$pdo = $db->getConnection();
|
||||
|
||||
header('Content-Type: application/json');
|
||||
$id = $_POST['id'] ?? null;
|
||||
$nome = $_POST['nome'] ?? '';
|
||||
$cliente = $_POST['cliente'] ?? '';
|
||||
$data = $_POST['data'] ?? null; // formato YYYY-MM-DD
|
||||
|
||||
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()]);
|
||||
if (!$nome) {
|
||||
echo json_encode(["success" => false, "message" => "Nome obbligatorio"]);
|
||||
exit;
|
||||
}
|
||||
|
||||
if ($id) {
|
||||
// UPDATE
|
||||
$sql = "UPDATE matrice SET nome = ?, cliente = ?, data_produzione = ? WHERE id = ?";
|
||||
$stmt = $pdo->prepare($sql);
|
||||
$ok = $stmt->execute([$nome, $cliente, $data, $id]);
|
||||
} else {
|
||||
// INSERT
|
||||
$sql = "INSERT INTO matrice (nome, cliente, data_produzione) VALUES (?,?,?)";
|
||||
$stmt = $pdo->prepare($sql);
|
||||
$ok = $stmt->execute([$nome, $cliente, $data]);
|
||||
}
|
||||
|
||||
echo json_encode(["success" => $ok]);
|
||||
|
||||
Reference in New Issue
Block a user