-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadmin_update.php
84 lines (58 loc) · 2.19 KB
/
admin_update.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
<?php
@include 'config.php';
$id = $_GET['edit'];
if(isset($_POST['update_product'])){
$product_name = $_POST['product_name'];
$product_price = $_POST['product_price'];
$product_image = $_FILES['product_image']['name'];
$product_image_tmp_name = $_FILES['product_image']['tmp_name'];
$product_image_folder = 'uploaded_img/'.$product_image;
if(empty($product_name) || empty($product_price) || empty($product_image)){
$message[] = 'please fill out all!';
}else{
$update_data = "UPDATE products SET name='$product_name', price='$product_price', image='$product_image' WHERE id = '$id'";
$upload = mysqli_query($conn, $update_data);
if($upload){
move_uploaded_file($product_image_tmp_name, $product_image_folder);
header('location:admin_page.php');
}else{
$$message[] = 'please fill out all!';
}
}
};
?>
<!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">
<link rel="stylesheet" href="css/style.css">
</head>
<body>
<?php
if(isset($message)){
foreach($message as $message){
echo '<span class="message">'.$message.'</span>';
}
}
?>
<div class="container">
<div class="admin-product-form-container centered">
<?php
$select = mysqli_query($conn, "SELECT * FROM products WHERE id = '$id'");
while($row = mysqli_fetch_assoc($select)){
?>
<form action="" method="post" enctype="multipart/form-data">
<h3 class="title">update the product</h3>
<input type="text" class="box" name="product_name" value="<?php echo $row['name']; ?>" placeholder="enter the product name">
<input type="number" min="0" class="box" name="product_price" value="<?php echo $row['price']; ?>" placeholder="enter the product price">
<input type="file" class="box" name="product_image" accept="image/png, image/jpeg, image/jpg">
<input type="submit" value="update product" name="update_product" class="btn">
<a href="admin_page.php" class="btn">go back!</a>
</form>
<?php }; ?>
</div>
</div>
</body>
</html>