obliczanie dziala, dodanie posta

This commit is contained in:
konradm 2024-11-13 14:47:17 +01:00
parent 2fbf0bb91d
commit b35221a086
6 changed files with 77 additions and 5 deletions

View File

@ -31,10 +31,11 @@
<label id="cena">Calculate ...</label> <label id="cena">Calculate ...</label>
<label for="liters">Ile litrów?</label> Ile litrow?</br>
<input type="text" id="liters" name="liters"> <input id = "ile_litrow"></input></br>
<input id = "oblicz" type="button" value="OBLICZ">
<input type="submit" value="OBLICZ">
<p id="wynik"></p>
</form> </form>
</div> </div>
@ -43,9 +44,20 @@
</div> </div>
</div> </div>
<div class="post">
<h2>Dodaj rodzaj paliwa</h2>
Nazwa:</br>
<input id="name" type="text" placeholder="nazwa"></br></br>
Cena:</br>
<input id="price" type="number" placeholder = "cena"></br></br>
<button id = "button_dodaj">Dodaj</button>
</div>
<div class="footer"> <div class="footer">
Stronę opracował: 000000000000 Stronę opracował: 000000000000
</div> </div>
<script src="js/post.js"></script>
</body> </body>
</html> </html>

26
js/post.js Normal file
View File

@ -0,0 +1,26 @@
document.addEventListener('DOMContentLoaded', () => {
button_dodaj = document.getElementById("button_dodaj")
button_dodaj.addEventListener("click", () => {
data = {
nazwa: document.getElementById("name").value,
cena: document.getElementById("price").value
}
fetch("php/post.php", {
method: "POST",
headers: {
"Content-Type":"application/json",
},
body: JSON.stringify(data)
})
.then(response => response.json)
.then(data => {
console.log("Succes", data)
window.location.reload()
})
})
})

View File

@ -4,6 +4,7 @@ const cena = document.getElementById("cena");
let usersData = []; let usersData = [];
document.addEventListener('DOMContentLoaded', function() { document.addEventListener('DOMContentLoaded', function() {
fetch('php/gget.php') fetch('php/gget.php')
.then(response => response.json()) .then(response => response.json())
@ -40,3 +41,15 @@ fuelType.addEventListener('change', function() {
} }
}); });
document.getElementById("oblicz").addEventListener("click", () => {
const ile_litrow = document.getElementById("ile_litrow").value
const cena_paliwa = document.getElementById("cena").innerHTML
console.log(ile_litrow)
console.log(cena_paliwa)
const wynik = ile_litrow * cena_paliwa
console.log(wynik)
document.getElementById("wynik").innerHTML = wynik
})

View File

@ -1,6 +1,6 @@
<?php <?php
$polaczenie = mysqli_connect("172.19.0.2", "root", "secret", "db"); $polaczenie = mysqli_connect("localhost", "root", "", "db");
$kwerenda = mysqli_query($polaczenie, "SELECT * FROM paliwa ORDER BY id DESC LIMIT 3;"); $kwerenda = mysqli_query($polaczenie, "SELECT * FROM paliwa ORDER BY id DESC LIMIT 3;");

20
php/post.php Normal file
View File

@ -0,0 +1,20 @@
<?php
$dbhost = "localhost";
$dbuser = "root";
$dbpass = "";
$dbname = "db";
$con = mysqli_connect($dbhost, $dbuser, $dbpass, $dbname);
$rawData = file_get_contents('php://input');
$data = json_decode($rawData, true);
$kw = "INSERT INTO paliwa (nazwa, cena) VALUES ('{$data['nazwa']}', {$data['cena']} );";
echo json_encode($kw);
$ans = mysqli_query($con, $kw);
?>

1
token.txt Normal file
View File

@ -0,0 +1 @@
03abdf5412e60673d79cd8929fdd18a8bbb631b3