-
Notifications
You must be signed in to change notification settings - Fork 0
/
admin_update_product.php
112 lines (75 loc) · 3.46 KB
/
admin_update_product.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
101
102
103
104
105
106
107
108
109
110
111
112
<?php
include 'config.php';
session_start();
$admin_id = $_SESSION['admin_id'];
if(!isset($admin_id)){
header('location:login.php');
};
if(isset($_POST['update_product'])){
$update_p_id = $_POST['update_p_id'];
$name = mysqli_real_escape_string($conn, $_POST['name']);
$price = mysqli_real_escape_string($conn, $_POST['price']);
$details = mysqli_real_escape_string($conn, $_POST['details']);
mysqli_query($conn, "UPDATE `products` SET name = '$name', details = '$details', price = '$price' WHERE id = '$update_p_id'") or die('query failed');
$image = $_FILES['image']['name'];
$image_size = $_FILES['image']['size'];
$image_tmp_name = $_FILES['image']['tmp_name'];
$image_folter = 'uploaded_img/'.$image;
$old_image = $_POST['update_p_image'];
if(!empty($image)){
if($image_size > 2000000){
$message[] = 'image file size is too large!';
}else{
mysqli_query($conn, "UPDATE `products` SET image = '$image' WHERE id = '$update_p_id'") or die('query failed');
move_uploaded_file($image_tmp_name, $image_folter);
unlink('uploaded_img/'.$old_image);
//$message[] = 'وێنەکە بە سەرکەوتوویی نوێکرایەوە';
}
}
$message[] = 'بەرهەمەکە بە سەرکەوتوویی نوێکرایەوە';
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>update product</title>
<!-- font awesome cdn link -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css">
<!-- custom admin css file link -->
<link rel="stylesheet" href="css/admin_style.css">
</head>
<body>
<?php include 'admin_header.php'; ?>
<section class="update-product">
<?php
$update_id = $_GET['update'];
$select_products = mysqli_query($conn, "SELECT * FROM `products` WHERE id = '$update_id'") or die('query failed');
if(mysqli_num_rows($select_products) > 0){
while($fetch_products = mysqli_fetch_assoc($select_products)){
?>
<div class="direction" style="direction: rtl;">
<form action="" method="post" enctype="multipart/form-data">
<img src="uploaded_img/<?php echo $fetch_products['image']; ?>" class="image" alt="">
<input type="hidden" value="<?php echo $fetch_products['id']; ?>" name="update_p_id">
<input type="hidden" value="<?php echo $fetch_products['image']; ?>" name="update_p_image">
<input type="text" class="box" value="<?php echo $fetch_products['name']; ?>" required placeholder="update product name" name="name">
<input type="number" min="0" class="box" value="<?php echo $fetch_products['price']; ?>" required placeholder="update product price" name="price">
<textarea name="details" class="box" required placeholder="update product details" cols="30" rows="10"><?php echo $fetch_products['details']; ?></textarea>
<input type="file" accept="image/jpg, image/jpeg, image/png" class="box" name="image">
<input type="submit" value="نوێكردنەوەی بەرهەمەكە" name="update_product" class="btn">
<a href="admin_products.php" class="option-btn">گەڕانەوە</a>
</form>
</div>
<?php
}
}else{
echo '<p class="empty">هیچ بەرهەمێکی نوێکردنەوە هەڵبژێرە</p>';
}
?>
</section>
<script src="js/admin_script.js"></script>
</body>
</html>