-
Notifications
You must be signed in to change notification settings - Fork 0
/
Addproduct.php
202 lines (176 loc) · 7.68 KB
/
Addproduct.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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
-- Active: 1682557258003@@127.0.0.1@3306@sensidia
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "Sensidia";
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die("Connection failed ".$conn->connect_error);
} else {
echo "";
}
$sql = "SELECT
products.id,
products.product_type,
products.image,
products.name,
products.description,
products.price,
products.SKU,
book.weight,
dvd.size,
dimensions.height,
dimensions.width,
dimensions.length
FROM products
LEFT JOIN dvd ON products.id = dvd.product_id
LEFT JOIN furniture ON products.id = furniture.product_id
LEFT JOIN dimensions ON furniture.id = dimensions.furniture_id
LEFT JOIN book ON products.id = book.product_id";
$result = mysqli_query($conn, $sql);
?>
<!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>Add Your Product</title>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Montserrat:ital,wght@0,100;0,200;0,600;1,100;1,400;1,500;1,600&display=swap" rel="stylesheet">
<link rel="stylesheet" href="src/index.css">
<link rel="stylesheet" href="src/formpage.css">
</head>
<body>
<header>
<h1>
Add Your Product!
</h1>
<p>We Accept Books, DVDs and Furnitures</p>
<a href="./firstpage.php">
<button>
Go Back
</button>
</a>
</header>
<main>
<div class= "product-form-div">
<form action="" method="POST" class="product-form" id="product-form" name="product-form" enctype="multipart/form-data" >
<label for="image">Image: </label>
<input type="text" id="image" name="image" required placeholder="Place an Link Image - Provide the Image">
<label for="SKU">SKU: </label>
<input type="text" name="SKU" id="SKU" placeholder="Unique Code Identificator">
<br>
<label for="name">Name *: </label>
<input type="text" id="name" name="name" required placeholder="Provide the product name">
<br>
<label for="price">Price($) *:</label>
<input type="number" id="price" name="price" step="0.01" required placeholder="Provide the price">
<br>
<label for="product_type" class="productType" >Product Type</label>
<select name="product_type" id="productType" >
<option value="null" placeholder="Choose One!">Choose One!</option>
<option value="dvd">DVD</option>
<option value="book">Book</option>
<option value="furniture">Furniture</option>
</select>
<br>
<div class="DescriptionProduct">
<div id="DVD">
<label for="size">Size(MB) *:</label>
<input type="number" id="size" name="size" placeholder="What are the MBs?">
<br>
</div>
<div id="Book">
<label for="weight">Weight(KG) *:</label>
<input type="number" id="weight" name="weight" step="0.001" placeholder="The book's Weight?">
<br>
</div>
<div id="dimensions">
<label for="height">Height(CM) *:</label>
<input type="number" id="height" name="height" step="0.01" placeholder="Product's Height please">
<br>
<label for="width">Width(CM) *:</label>
<input type="number" id="width" name="width" step="0.01" placeholder="Product's Width please">
<br>
<label for="length">Length(CM) *:</label>
<input type="number" id="length" name="length" step="0.01" placeholder="Product's Lenght please">
<br>
</div>
<label for="description">Description *:</label>
<textarea name="description" id="description" required placeholder="Describe more about your product."></textarea>
<div class="buttons">
<button id="save-product-btn" name="save-product-btn" type="submit">
Save
</button>
<a>
<button>
Cancel
</button>
</a>
</div>
</div>
</form>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script>
$(document).ready(function() {
$("#save-product-btn").click(function() {
$.ajax({
url: "./src/formProcessor.php",
type: "POST",
data: $("#product-form").serialize(),
success: function(response) {
$("./src/formProcessor.php").html(response);
}
});
});
});
</script>
<script>
document.getElementById('DVD').style.display = 'none';
document.getElementById('Book').style.display = 'none';
document.getElementById('dimensions').style.display = 'none';
document.getElementById('productType').addEventListener('change', function() {
document.getElementById('DVD').style.display = 'none';
document.getElementById('Book').style.display = 'none';
document.getElementById('dimensions').style.display = 'none';
var option =this.value;
if (option == 'book') {
document.getElementById('Book').style.display = 'block';
}else if (option == 'dvd') {
document.getElementById('DVD').style.display = 'block';
}else if (option == 'furniture') {
document.getElementById('dimensions').style.display = 'block';
}
});
</script>
</div>
</main>
<footer id="footer">
<p>© 2023 - Scandiweb Test Assigment</p>
<script>
var footer = document.getElementById('footer');
var lastScrollPosition = 0;
window.addEventListener('scroll', function() {
var currentScrollPosition = window.scrollY || document.documentElement.scrollTop;
if (currentScrollPosition > lastScrollPosition) {
// Scroll para baixo
if (currentScrollPosition + window.innerHeight >= document.documentElement.scrollHeight) {
// Chegou ao final da página, mostra o footer
footer.style.bottom = '0';
}
} else {
// Scroll para cima
if (currentScrollPosition + window.innerHeight < document.documentElement.scrollHeight - footer.clientHeight) {
// Ainda não chegou ao final da página, esconde o footer
footer.style.bottom = '-100px';
}
}
lastScrollPosition = currentScrollPosition;
});
</script>
</footer>
</body>
</html>