-
Notifications
You must be signed in to change notification settings - Fork 0
/
adminPanel.php
117 lines (91 loc) · 3.59 KB
/
adminPanel.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
113
114
115
116
117
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>ADMIN PANEL</title>
<link rel="stylesheet" href="./styles/adminPanel.css">
</head>
<body>
<div class="app">
<a href="index.php" class="back-btn">
<div></div>
</a>
<button class="add-product-btn">
+
</button>
<div class="add-product-form">
<form method="POST" reuire>
<label for="name">Nazwa produktu</label>
<input type="text" id="name" name="name" required>
<label for="category">Kategoria</label>
<select id="category" name="category">
<option value="switch">switch</option>
<option value="router">router</option>
<option value="other">inne</option>
</select>
<label for="price">Cena</label>
<input type="number" id="price" name="price" required>
<label for="count">Ilość</label>
<input type="number" id="count" name="count" required>
<label for="image">Link do obrazka</label>
<input type="text" id="image" name="image" required>
<button>dodaj produkt</button>
</form>
</div>
<?php
$conn = mysqli_connect('remotemysql.com', '3Atj7OvE8S', 'D0TFKvjonl', '3Atj7OvE8S');
if (!empty($_POST['name']) && !empty($_POST['price']) && !empty($_POST['count'])) {
$name = $_POST['name'];
$category = $_POST['category'];
$price = $_POST['price'];
$count = $_POST['count'];
$image = $_POST['image'];
$query = "INSERT INTO products VALUES('0', '$name', '$category', '$price', '$count', '$image')";
if (mysqli_query($conn, $query));
echo "<script>alert('Produkt pomyślnie dodany do bazy!')</script>";
}
?>
<div class="products-list">
<?php
$conn = mysqli_connect('remotemysql.com', '3Atj7OvE8S', 'D0TFKvjonl', '3Atj7OvE8S');
$result = mysqli_query($conn, "SELECT * FROM products");
if (mysqli_num_rows($result) > 0) {
while ($row = mysqli_fetch_array($result)) {
echo "<div class='product'><img src='" . $row['image'] . "'/><div><p>" . $row['name'] . "</p><span class='price'>Cena: " . $row['price'] . " PLN</span><button name='delete-btn' class='delete-btn' data-btnId='" . $row['id_p'] . "'>usuń produkt</button></div></div>";
}
}
?>
</div>
</div>
<script src="//code.jquery.com/jquery-1.11.0.min.js"></script>
<script>
const addProductBtn = document.querySelector('.add-product-btn')
const addProductForm = document.querySelector('.add-product-form')
const toggleAddProductForm = () => {
addProductForm.classList.toggle('form--active')
addProductBtn.classList.toggle('btn--active')
}
addProductBtn.addEventListener('click', toggleAddProductForm)
if (window.history.replaceState) {
window.history.replaceState(null, null, window.location.href);
}
</script>
<script>
$(document).ready(function() {
// --------------------------------- permanent product removing
$(document).on('click', '.delete-btn', function() {
let removeId = $(this).attr('data-btnId');
let ajaxurl = 'ajax.php',
data = {
'removeId': removeId
};
$.post(ajaxurl, data)
$('.products-list').load("ajax.php", {
updatePanel: true
})
})
});
</script>
</body>
</html>