-
Notifications
You must be signed in to change notification settings - Fork 0
/
process_update_bw.php
80 lines (72 loc) · 2.83 KB
/
process_update_bw.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
<?php
include './Includes/connection.php';
session_start();
if ($_SERVER["REQUEST_METHOD"] == "POST") {
// Create a new instance of the connection class
$db = new connection();
$conn = $db->getConnection();
$itemId = $_POST['item_id'];
$productName = $_POST['productName'];
$category = $_POST['category'];
$brand = $_POST['brand'];
$sizeOptions = implode(', ', $_POST['sizeOptions']);
$material = $_POST['material'];
$price = $_POST['price'];
$quantityAvailable = $_POST['quantityAvailable'];
$description = $_POST['description'];
$careInstructions = $_POST['careInstructions'];
$tags = $_POST['tags'];
$availabilityStatus = $_POST['availabilityStatus'];
$discounts = $_POST['discounts'];
// Handle uploaded images only if new images are selected
if (!empty($_FILES['images']['name'][0])) {
$targetDirectory = "./uploaded_img/";
$uploadedImages = array();
foreach ($_FILES['images']['tmp_name'] as $key => $tmp_name) {
$targetFile = $targetDirectory . basename($_FILES['images']['name'][$key]);
move_uploaded_file($tmp_name, $targetFile);
$uploadedImages[] = $targetFile;
}
// Update data in the database with new images
$stmt = $conn->prepare("UPDATE clothing_items_bridal_wear SET
productName = ?,
category = ?,
brand = ?,
sizeOptions = ?,
material = ?,
price = ?,
quantityAvailable = ?,
description = ?,
careInstructions = ?,
tags = ?,
availabilityStatus = ?,
discounts = ?,
images = ?
WHERE id = ?");
$stmt->execute([$productName, $category, $brand, $sizeOptions, $material, $price, $quantityAvailable, $description, $careInstructions, $tags, $availabilityStatus, $discounts, implode(', ', $uploadedImages), $itemId]);
} else {
// Update data in the database without changing the existing images
$stmt = $conn->prepare("UPDATE clothing_items_bridal_wear SET
productName = ?,
category = ?,
brand = ?,
sizeOptions = ?,
material = ?,
price = ?,
quantityAvailable = ?,
description = ?,
careInstructions = ?,
tags = ?,
availabilityStatus = ?,
discounts = ?
WHERE id = ?");
$stmt->execute([$productName, $category, $brand, $sizeOptions, $material, $price, $quantityAvailable, $description, $careInstructions, $tags, $availabilityStatus, $discounts, $itemId]);
}
// Redirect back to the admin page after updating
$_SESSION['success'] = 'Item updated successfully!';
header('location: view_item_BW.php');
exit();
} else {
echo "Invalid request!";
}
?>