-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathadd_products.php
100 lines (85 loc) · 4.69 KB
/
add_products.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
<?php
include './include/check_login.php';
include './include/connection.php';
include_once 'include/admin-main.php';
include('access_control.php');
$addProductMsg = '';
$deleteProductMsg = '';
// Add Product Form Handling
if (isset($_POST['add_product'])) {
$product_name = $_POST['product_name'];
$product_base = $_POST['product_base'];
$product_color = $_POST['product_color'];
// Check if the product already exists
$checkQuery = mysqli_query($con, "SELECT * FROM kits_product WHERE product_name = '$product_name' AND product_base = '$product_base' AND product_color = '$product_color'");
$rowCount = mysqli_num_rows($checkQuery);
$checkQuery = mysqli_query($con, "SELECT * FROM products WHERE product_name = '$product_name' AND product_base = '$product_base' AND product_color = '$product_color'");
$rowCount = mysqli_num_rows($checkQuery);
$checkQuery = mysqli_query($con, "SELECT * FROM sheets_product WHERE product_name = '$product_name' AND product_base = '$product_base' AND product_color = '$product_color'");
$rowCount = mysqli_num_rows($checkQuery);
$checkQuery = mysqli_query($con, "SELECT * FROM sheets_production_product WHERE product_name = '$product_name' AND product_base = '$product_base' AND product_color = '$product_color'");
$rowCount = mysqli_num_rows($checkQuery);
if ($rowCount > 0) {
$addProductMsg = "<p style='color: red;font-size: medium;text-align: center;'>Product already exists</p>";
} else {
// Insert into products table
$insertKitsProductQuery = "INSERT INTO products (product_name, product_base, product_color) VALUES ('$product_name', '$product_base', '$product_color')";
mysqli_query($con, $insertKitsProductQuery);
// Insert into kits_product table
$insertKitsProductQuery = "INSERT INTO kits_product (product_name, product_base, product_color) VALUES ('$product_name', '$product_base', '$product_color')";
mysqli_query($con, $insertKitsProductQuery);
// Insert into sheets table
$insertSheetsProductQuery = "INSERT INTO sheets_product (product_name, product_base, product_color) VALUES ('$product_name', '$product_base', '$product_color')";
mysqli_query($con, $insertSheetsProductQuery);
// Insert into sheets production table
$insertProductionProductQuery = "INSERT INTO sheets_production_product (product_name, product_base, product_color) VALUES ('$product_name', '$product_base', '$product_color')";
mysqli_query($con, $insertProductionProductQuery);
// Check if insertion was successful
if (mysqli_affected_rows($con) > 0) {
$addProductMsg = "<p style='color: green;font-size: medium;text-align: center;'>Product added successfully</p>";
} else {
$addProductMsg = "<p style='color: red;font-size: medium;text-align: center;'>Failed to add product</p>";
}
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Product Management</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
</head>
<body>
<div class="container">
<div class="row justify-content-center">
<div class="col-md-6">
<div class="card mt-5">
<div class="card-header">
<h2>Add Product</h2>
</div>
<div class="card-body">
<?php echo $addProductMsg; ?>
<form action="" method="post">
<div class="form-group">
<label for="product_name">Product Name</label>
<input type="text" name="product_name" id="product_name" class="form-control" required>
</div>
<div class="form-group">
<label for="product_base">Product Base Color</label>
<input type="text" name="product_base" id="product_base" class="form-control" required>
</div>
<div class="form-group">
<label for="product_color">Product Color</label>
<input type="text" name="product_color" id="product_color" class="form-control" required>
</div>
<button type="submit" class="btn btn-primary" name="add_product">Add Product</button>
</form>
</div>
</div>
</div>
</div>
</div>
</body>
</html>