-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproducts_save.php
More file actions
39 lines (33 loc) · 1.86 KB
/
Copy pathproducts_save.php
File metadata and controls
39 lines (33 loc) · 1.86 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
39
<?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);
$stmt = $pdo->prepare("SELECT id FROM products WHERE product_code = ?");
$stmt->execute([$product_code]);
if ($stmt->fetch()) {
echo json_encode(['success'=>false, 'message'=>'The article number already exists!']);
exit;
}
$stmt = $pdo->prepare("INSERT INTO products (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 ) VALUES ( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? )");
$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 ]);
echo json_encode(['success'=>$res]);