fixed tested components
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
header('Content-Type: application/json');
|
||||
|
||||
ini_set('display_errors', 1);
|
||||
error_reporting(E_ALL);
|
||||
|
||||
require_once(__DIR__ . '/include/headscript.php'); // così hai Auth + $iduserlogin + DBHandlerSelect
|
||||
|
||||
try {
|
||||
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
|
||||
throw new Exception('Invalid request method');
|
||||
}
|
||||
|
||||
$iddatadb = isset($_POST['iddatadb']) ? (int)$_POST['iddatadb'] : 0;
|
||||
$part_description = isset($_POST['part_description']) ? trim($_POST['part_description']) : '';
|
||||
|
||||
if ($iddatadb <= 0) {
|
||||
throw new Exception('Missing iddatadb');
|
||||
}
|
||||
|
||||
if ($part_description === '') {
|
||||
throw new Exception('Part description is empty');
|
||||
}
|
||||
|
||||
// (opzionale ma consigliato) limita lunghezza come da DB varchar(255)
|
||||
if (mb_strlen($part_description) > 255) {
|
||||
$part_description = mb_substr($part_description, 0, 255);
|
||||
}
|
||||
|
||||
$db = DBHandlerSelect::getInstance();
|
||||
$pdo = $db->getConnection();
|
||||
|
||||
// Insert minimal
|
||||
$stmt = $pdo->prepare("
|
||||
INSERT INTO identification_parts (iddatadb, part_number, part_description)
|
||||
VALUES (?, 1, ?)
|
||||
");
|
||||
$ok = $stmt->execute([$iddatadb, $part_description]);
|
||||
|
||||
if (!$ok) {
|
||||
throw new Exception('Insert failed');
|
||||
}
|
||||
|
||||
echo json_encode([
|
||||
'success' => true,
|
||||
'message' => 'Part added',
|
||||
'id' => $pdo->lastInsertId()
|
||||
]);
|
||||
} catch (Exception $e) {
|
||||
echo json_encode(['success' => false, 'message' => $e->getMessage()]);
|
||||
}
|
||||
exit;
|
||||
Reference in New Issue
Block a user