Compare commits

..

No commits in common. "2d1185ff074c75125d7904d5a91b70a1ef71ee32" and "2fbf0bb91d77589f0cd4556cd95e6e220643f636" have entirely different histories.

8 changed files with 111 additions and 110 deletions

37
@ Normal file
View File

@ -0,0 +1,37 @@
document.addEventListener('DOMContentLoaded', function() {
//const imieSelect = document.getElementById('imie');
let usersData = [];
imieSelect.addEventListener('focus', function() {
fetch('php/gget.php')
.then(response => response.json())
.then(data => {
/*
usersData = data;
imieSelect.innerHTML = "";
data.forEach(dane => {
const option = document.createElement('option');
option.value = dane.id;
option.textContent = dane.imie + " " + dane.nazwisko;
imieSelect.appendChild(option);
});
*/
console.log(data);
})
.catch(error => console.error('Error fetching data:', error));
});
/*
imieSelect.addEventListener('change', function() {
const selectedId = imieSelect.value;
const selectedPerson = usersData.find(dane => dane.id == selectedId);
if (selectedPerson && selectedPerson.photo) {
photoDisplay.src = 'data:image/jpeg;base64,' + selectedPerson.photo;
} else {
photoDisplay.src = '';
}
});
*/
});

View File

@ -6,8 +6,7 @@
<title>Całodobowa stacja paliw</title>
<link rel="stylesheet" href="css/style.css">
<script type="module" src="js/get.js"></script>
<script type="module" src="js/post.js"></script>
<script type="module" src="js/script.js"></script>
</head>
<body>
@ -44,16 +43,6 @@
</div>
</div>
<div>
<h2>Orientacyjny koszt paliwa</h2>
<input type="text" id="fuel" name="name">
<input type="text" id="price" name="price">
<button type="button" id="btn">Oblicz</button>
</div>
<div class="footer">
Stronę opracował: 000000000000
</div>

View File

@ -1,42 +1,35 @@
const fuelType = document.getElementById('fuel-type');
const cena = document.getElementById("cena");
let usersData = [];
document.addEventListener('DOMContentLoaded', function() {
fetch('php/get.php')
const imieSelect = document.getElementById('imie');
const photoDisplay = document.createElement('img');
photoDisplay.style.width = "200px";
photoDisplay.style.height = "auto";
document.getElementById('prawy').appendChild(photoDisplay);
let usersData = [];
imieSelect.addEventListener('focus', function() {
fetch('get.php')
.then(response => response.json())
.then(data => {
usersData = data;
data.forEach(row => {
imieSelect.innerHTML = "";
data.forEach(dane => {
const option = document.createElement('option');
option.value = row["nazwa"];
option.textContent = row["nazwa"];
fuelType.appendChild(option);
console.log(row);
option.value = dane.id;
option.textContent = dane.imie + " " + dane.nazwisko;
imieSelect.appendChild(option);
});
console.log(data);
})
.catch(error => console.error('Error fetching data:', error));
});
});
fuelType.addEventListener('change', function() {
console.log("Zmiana wybranego paliwa");
const selectedId = fuelType.value;
const selectedFuel = usersData.find(dane => dane.nazwa === selectedId);
cena.textContent = selectedFuel["cena"];
console.log("mati");
if (selectedFuel) {
const cena = selectedFuel.cena;
console.log("Cena wybranego paliwa:", cena);
imieSelect.addEventListener('change', function() {
const selectedId = imieSelect.value;
const selectedPerson = usersData.find(dane => dane.id == selectedId);
if (selectedPerson && selectedPerson.photo) {
photoDisplay.src = 'data:image/jpeg;base64,' + selectedPerson.photo;
} else {
console.error("Nie znaleziono ceny dla wybranego paliwa");
photoDisplay.src = '';
}
});
});

View File

@ -1,36 +0,0 @@
document.getElementById('btn').addEventListener('click', async () => {
const fuelType = document.getElementById('fuel').value;
const liters = document.getElementById('price').value;
// Spakuj dane w formacie JSON
const data = {
nazwa: fuelType,
cena: parseFloat(liters) // konwertuj na liczbę, jeśli wartość jest liczbową
};
console.log("ok");
try {
// Wykonaj żądanie POST
const response = await fetch('php/post.php', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(data)
});
// Przetwarzanie odpowiedzi
if (response.ok) {
const result = await response.json();
console.log('Odpowiedź serwera:', result);
alert(`Koszt paliwa: ${result.cost}`);
} else {
console.error('Błąd:', response.statusText);
}
} catch (error) {
console.error('Błąd:', error);
}
});

42
js/script.js Normal file
View File

@ -0,0 +1,42 @@
const fuelType = document.getElementById('fuel-type');
const cena = document.getElementById("cena");
let usersData = [];
document.addEventListener('DOMContentLoaded', function() {
fetch('php/gget.php')
.then(response => response.json())
.then(data => {
usersData = data;
data.forEach(row => {
const option = document.createElement('option');
option.value = row["nazwa"];
option.textContent = row["nazwa"];
fuelType.appendChild(option);
console.log(row);
});
console.log(data);
})
.catch(error => console.error('Error fetching data:', error));
});
fuelType.addEventListener('change', function() {
console.log("Zmiana wybranego paliwa");
const selectedId = fuelType.value;
const selectedFuel = usersData.find(dane => dane.nazwa === selectedId);
cena.textContent = selectedFuel["cena"];
console.log("mati");
if (selectedFuel) {
const cena = selectedFuel.cena;
console.log("Cena wybranego paliwa:", cena);
} else {
console.error("Nie znaleziono ceny dla wybranego paliwa");
}
});

View File

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

View File

@ -1,20 +0,0 @@
<?php
$dbhost = "172.18.0.3";
$dbuser = "root";
$dbpass = "secret";
$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);
?>

View File

@ -1,4 +0,0 @@
curl -X POST http://localhost:8080/p14.11/php/post.php \
-H "Content-Type: application/json" \
-d '{"nazwa": "Diesel", "cena": 5.25}'