-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdateProductProcess.php
More file actions
95 lines (60 loc) · 2.18 KB
/
updateProductProcess.php
File metadata and controls
95 lines (60 loc) · 2.18 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
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
<?php
include "connection.php";
$title = $_POST["t"];
$qty = $_POST["q"];
$price = $_POST["p"];
$desc = $_POST["d"];
$dwk = $_POST["dwk"];
$dok = $_POST["dok"];
$pid = $_POST["pid"];
if(empty($title)){
echo("Please insert your product name");
}else if(empty($qty)){
echo("Please add a product quantity");
}else if(empty($price)){
echo("Please insert your product price");
}else if(empty($dwk)){
echo("Please insert delivery price within kandy");
}else if(empty($dok)){
echo("Please insert delivery price out of kandy");
}else{
Database::iud("UPDATE `product` SET `title` = '" . $title . "' , `description` = '" . $desc . "' , `qty` = '" . $qty . "' , `price` = '" . $price . "' ,
`delivery_fee_Kandy` = '" . $dwk . "' , `delivery_fee_other` = '" . $dok . "' WHERE `id` = '" . $pid . "'");
echo ("Product has been updated");
$length = sizeof($_FILES);
if ($length <= 1 && $length > 0){
$allowed_img_extentions = array("image/jpeg", "image/png", "image/svg+xml");
$image_rs = Database::search("SELECT * FROM `product_img` WHERE `product_id` = '".$pid."' ");
$image_num = $image_rs->num_rows;// img_rs il eththanai rows irukkiradhu ena paarthal
for($y = 0; $y < $image_num; $y++){
$image_data = $image_rs->fetch_assoc();
unlink($image_data["img_path"]);
Database::iud("DELETE FROM `product_img` WHERE `product_id` = '".$pid."' ");
}
for ($x = 0; $x < $length; $x++) {
if (isset($_FILES["i" . $x])) {
$image_file = $_FILES["i" . $x];
$file_extention = $image_file["type"];
if (in_array($file_extention, $allowed_img_extentions)) {
$new_img_extension;
if ($file_extention == "image/jpeg") {
$new_img_extension = ".jpeg";
} else if ($file_extention == "image/png") {
$new_img_extension = ".png";
} else if ($file_extention == "image/svg+xml") {
$new_img_extension = ".svg";
}
$file_name = "img//products//" . $title . $x . uniqid() . $new_img_extension;
move_uploaded_file($image_file["tmp_name"], $file_name);
Database::iud("INSERT INTO `product_img` (`img_path` , `product_id`) VALUES ('" . $file_name . "' , '" . $pid . "')");
} else {
echo ("invalid file type");
}
}
}
// echo ("success");
}
// }else {
// echo ("Invalid image count");
// }
}