25 lines
836 B
PHP
25 lines
836 B
PHP
<?php
|
|
include('include/headscript.php');
|
|
header('Content-Type: application/json');
|
|
|
|
$category = trim($_POST['category'] ?? '');
|
|
$item_name = trim($_POST['item_name'] ?? '');
|
|
$item_code = trim($_POST['item_code'] ?? '');
|
|
|
|
$allowed = ['PACKAGING_TYPE', 'BOX', 'PALLET', 'OTHER'];
|
|
if (!in_array($category, $allowed, true) || $item_name === '' || $item_code === '') {
|
|
echo json_encode(['success' => false, 'message' => 'Invalid input']);
|
|
exit;
|
|
}
|
|
|
|
$db = DBHandlerSelect::getInstance();
|
|
$pdo = $db->getConnection();
|
|
|
|
try {
|
|
$stmt = $pdo->prepare("INSERT INTO packaging_items (category, item_name, item_code) VALUES (?,?,?)");
|
|
$stmt->execute([$category, $item_name, $item_code]);
|
|
echo json_encode(['success' => true]);
|
|
} catch (PDOException $e) {
|
|
echo json_encode(['success' => false, 'message' => $e->getMessage()]);
|
|
}
|