-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdateItemController.php
More file actions
44 lines (39 loc) · 1.2 KB
/
updateItemController.php
File metadata and controls
44 lines (39 loc) · 1.2 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
<?php
include_once "./dbconnect.php";
$product_id=$_POST['product_id'];
$p_name= $_POST['p_name'];
$p_desc= $_POST['p_desc'];
$p_price= $_POST['p_price'];
$category= $_POST['category'];
if( isset($_FILES['newImage']) ){
$location="./uploads/";
$img = $_FILES['newImage']['name'];
$tmp = $_FILES['newImage']['tmp_name'];
$dir = '../uploads/';
$ext = strtolower(pathinfo($img, PATHINFO_EXTENSION));
$valid_extensions = array('jpeg', 'jpg', 'png', 'gif','webp');
$image =rand(1000,1000000).".".$ext;
$final_image=$location. $image;
if (in_array($ext, $valid_extensions)) {
$path = UPLOAD_PATH . $image;
move_uploaded_file($tmp, $dir.$image);
}
}else{
$final_image=$_POST['existingImage'];
}
$updateItem = mysqli_query($conn,"UPDATE products SET
product_title='$p_name',
product_desc='$p_desc',
product_price=$p_price,
cat_id=$category,
product_img1='$final_image'
WHERE products_id=$product_id");
if($updateItem)
{
echo "true";
}
// else
// {
// echo mysqli_error($conn);
// }
?>