100 lines
3.8 KiB
PHP
100 lines
3.8 KiB
PHP
<?php
|
|
// fillparts.php
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['ididentificationparts'])) {
|
|
include '../Connections/cmctrfdb.php'; // Assicurati che il percorso sia corretto
|
|
|
|
$ididentificationparts = $_POST['ididentificationparts'];
|
|
$partsidnumber = $_POST['partsidnumber'] ?? '';
|
|
$description_identificationparts = $_POST['description_identificationparts'] ?? '';
|
|
$article_identificationparts = $_POST['article_identificationparts'] ?? '';
|
|
$color_identificationparts = $_POST['color_identificationparts'] ?? '';
|
|
$material_identificationparts = $_POST['material_identificationparts'] ?? '';
|
|
$cmcreportnumber_identificationparts = $_POST['cmcreportnumber_identificationparts'] ?? '';
|
|
$cmcreportdate_identificationparts = $_POST['cmcreportdate_identificationparts'] ?? '';
|
|
|
|
// Connessione al database
|
|
$conn = mysqli_connect($servername, $username, $password, $dbname);
|
|
if (!$conn) {
|
|
die("Connessione fallita: " . mysqli_connect_error());
|
|
}
|
|
|
|
// Preparazione della query SQL. Utilizzo di un approccio dinamico per gestire i campi.
|
|
$updates = [];
|
|
$params = [];
|
|
$types = '';
|
|
|
|
if (!empty($partsidnumber)) {
|
|
$updates[] = "partsidnumber = ?";
|
|
$params[] = &$partsidnumber;
|
|
$types .= 's';
|
|
}
|
|
|
|
if (!empty($description_identificationparts)) {
|
|
$updates[] = "description_identificationparts = ?";
|
|
$params[] = &$description_identificationparts;
|
|
$types .= 's';
|
|
}
|
|
|
|
if (!empty($article_identificationparts)) {
|
|
$updates[] = "article_identificationparts = ?";
|
|
$params[] = &$article_identificationparts;
|
|
$types .= 's';
|
|
}
|
|
|
|
if (!empty($color_identificationparts)) {
|
|
$updates[] = "color_identificationparts = ?";
|
|
$params[] = &$color_identificationparts;
|
|
$types .= 's';
|
|
}
|
|
|
|
if (!empty($material_identificationparts)) {
|
|
$updates[] = "material_identificationparts = ?";
|
|
$params[] = &$material_identificationparts;
|
|
$types .= 's';
|
|
}
|
|
|
|
if (!empty($cmcreportnumber_identificationparts)) {
|
|
$updates[] = "cmcreportnumber_identificationparts = ?";
|
|
$params[] = &$cmcreportnumber_identificationparts;
|
|
$types .= 's';
|
|
}
|
|
|
|
if (!empty($cmcreportdate_identificationparts)) {
|
|
$updates[] = "cmcreportdate_identificationparts = ?";
|
|
$params[] = &$cmcreportdate_identificationparts;
|
|
$types .= 's';
|
|
}
|
|
|
|
if (count($updates) > 0) {
|
|
$query = "UPDATE identificationparts SET " . implode(', ', $updates) . " WHERE ididentificationparts = ?";
|
|
$params[] = &$ididentificationparts;
|
|
$types .= 'i';
|
|
|
|
$stmt = $conn->prepare($query);
|
|
if ($stmt) {
|
|
$stmt->bind_param($types, ...$params);
|
|
if ($stmt->execute()) {
|
|
// Verifica se sono state effettuate modifiche
|
|
if ($stmt->affected_rows > 0) {
|
|
echo json_encode(['success' => true, 'message' => 'Aggiornamento effettuato con successo']);
|
|
} else {
|
|
echo json_encode(['success' => false, 'message' => 'Nessun aggiornamento necessario o id non trovato']);
|
|
}
|
|
} else {
|
|
echo json_encode(['success' => false, 'message' => 'Errore nell\'esecuzione della query']);
|
|
}
|
|
$stmt->close();
|
|
} else {
|
|
echo json_encode(['success' => false, 'message' => 'Errore nella preparazione della query']);
|
|
}
|
|
} else {
|
|
echo json_encode(['success' => false, 'message' => 'Nessun campo da aggiornare']);
|
|
}
|
|
|
|
$conn->close();
|
|
} else {
|
|
// Gestire l'accesso non valido a questo file
|
|
header('HTTP/1.1 403 Forbidden');
|
|
echo json_encode(['success' => false, 'message' => 'Accesso negato o dati mancanti']);
|
|
}
|