-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadmin_page.php
111 lines (86 loc) · 3.16 KB
/
admin_page.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
<?php
@include 'config.php';
if(isset($_POST['add_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{
$insert = "INSERT INTO products(name, price, image) VALUES('$product_name', '$product_price', '$product_image')";
$upload = mysqli_query($conn,$insert);
if($upload){
move_uploaded_file($product_image_tmp_name, $product_image_folder);
$message[] = 'new product added successfully';
}else{
$message[] = 'could not add the product';
}
}
};
if(isset($_GET['delete'])){
$id = $_GET['delete'];
mysqli_query($conn, "DELETE FROM products WHERE id = $id");
header('location:admin_page.php');
};
?>
<!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>admin page</title>
<!-- font awesome cdn link -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/all.min.css">
<!-- custom css file link -->
<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">
<form action="<?php $_SERVER['PHP_SELF'] ?>" method="post" enctype="multipart/form-data">
<h3>add a new product</h3>
<input type="text" placeholder="enter product name" name="product_name" class="box">
<input type="number" placeholder="enter product price" name="product_price" class="box">
<input type="file" accept="image/png, image/jpeg, image/jpg" name="product_image" class="box">
<input type="submit" class="btn" name="add_product" value="add product">
</form>
</div>
<?php
$select = mysqli_query($conn, "SELECT * FROM products");
?>
<div class="product-display">
<table class="product-display-table">
<thead>
<tr>
<th>product image</th>
<th>product name</th>
<th>product price</th>
<th>action</th>
</tr>
</thead>
<?php while($row = mysqli_fetch_assoc($select)){ ?>
<tr>
<td><img src="uploaded_img/<?php echo $row['image']; ?>" height="100" alt=""></td>
<td><?php echo $row['name']; ?></td>
<td>$<?php echo $row['price']; ?>/-</td>
<td>
<a href="admin_update.php?edit=<?php echo $row['id']; ?>" class="btn"> <i class="fas fa-edit"></i> edit </a>
<a href="admin_page.php?delete=<?php echo $row['id']; ?>" class="btn"> <i class="fas fa-trash"></i> delete </a>
</td>
</tr>
<?php } ?>
</table>
</div>
</div>
</body>
</html>