-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproducts_update.php
More file actions
38 lines (34 loc) · 1.89 KB
/
Copy pathproducts_update.php
File metadata and controls
38 lines (34 loc) · 1.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
<?php
require_once 'includes/auth.php';
require_login();
require_csrf();
require_once 'includes/db.php';
$id = (int)$_POST['id'];
$product_code = trim($_POST['product_code'] ?? '');
$product_name = trim($_POST['product_name'] ?? '');
$product_type = trim($_POST['product_type'] ?? '');
$primary_type = trim($_POST['primary_type'] ?? '');
$shape = trim($_POST['shape'] ?? '');
$device = trim($_POST['device'] ?? '');
$accuracy = trim($_POST['accuracy'] ?? '');
$frequency = trim($_POST['frequency'] ?? '');
$primary_value = trim($_POST['primary_value'] ?? '');
$secondary_value = trim($_POST['secondary_value'] ?? '');
$extension = trim($_POST['extension'] ?? '');
$isolation_level = trim($_POST['isolation_level'] ?? '');
$cable_length = trim($_POST['cable_length'] ?? '');
$cable_type = trim($_POST['cable_type'] ?? '');
$connection_type = trim($_POST['connection_type'] ?? '');
$burden = trim($_POST['burden'] ?? '');
$additional_info = trim($_POST['additional_info'] ?? '');
$stock = trim($_POST['stock'] ?? 0);
// Duplicate check only if code has changed!
$stmt = $pdo->prepare("SELECT id FROM products WHERE product_code=? AND id<>?");
$stmt->execute([$product_code, $id]);
if ($stmt->fetch()) {
echo json_encode(['success'=>false, 'message'=>'The article number already exists!']);
exit;
}
$stmt = $pdo->prepare("UPDATE products SET product_code=?, product_name=?, product_type=?, primary_type=?, shape=?, device=?, accuracy=?, frequency=?, primary_value=?, secondary_value=?, extension=?, isolation_level=?, cable_length=?, cable_type=?, connection_type=?, burden=?, additional_info=?, stock=? WHERE id=?");
$res = $stmt->execute([$product_code, $product_name, $product_type, $primary_type, $shape, $device, $accuracy, $frequency, $primary_value, $secondary_value, $extension, $isolation_level, $cable_length, $cable_type, $connection_type, $burden, $additional_info, $stock, $id]);
echo json_encode(['success'=>$res]);