-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadd.php
58 lines (44 loc) · 1.5 KB
/
add.php
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<?php
require("inc/db.php");
if ($_POST) {
$barcode = 'SKU-'.uniqid($_POST['barcode']);
$name = ($_POST['name']);
$price = $_POST['price'];
$size = ($_POST['size']);
$weight = ($_POST['weight']);
$image = ($_POST['image']);
$height = $_POST['height'];
$width = ($_POST['width']);
$length = $_POST['length'];
// add new record in a table
try {
$sql = 'INSERT INTO products (barcode, name, price, size, weight, image, height, width, length)
VALUES '.'(:barcode, :name, :price, :size, :weight, :image, :height, :width, :length)';
// prepare sql and bind parameters
$stmt = $conn->prepare($sql);
$stmt->bindParam(":barcode", $barcode);
$stmt->bindParam(":name", $name);
$stmt->bindParam(":price", $price);
$stmt->bindParam(":size", $size);
$stmt->bindParam(":weight", $weight);
$stmt->bindParam(":image", $image);
$stmt->bindParam(":height", $height);
$stmt->bindParam(":width", $width);
$stmt->bindParam(":length", $length);
$stmt->execute();
// STATUS on creation new product
if ($stmt->rowCount()) {
header("Location: create.php?status=created");
exit();
}
header("Location: create.php?status=fail_create");
exit();
} catch (Exception $e) {
echo "Error " . $e->getMessage();
exit();
}
} else {
header("Location: create.php?status=fail_create");
exit();
}
?>