Compare commits
No commits in common. "aguzik" and "main" have entirely different histories.
19
index.html
19
index.html
|
@ -1,19 +0,0 @@
|
||||||
<!DOCTYPE html>
|
|
||||||
<html lang="en">
|
|
||||||
<head>
|
|
||||||
<meta charset="UTF-8">
|
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
||||||
<title>Document</title>
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<input type="file" name="zdjecie" id="zdjecie">
|
|
||||||
<button type="submit" id="submitZdj">Wyslij plik</button>
|
|
||||||
<script src="script.js"></script>
|
|
||||||
|
|
||||||
<select id="wybor">
|
|
||||||
<option value=""></option>
|
|
||||||
</select><br>
|
|
||||||
<img src="" alt="" id="img">
|
|
||||||
|
|
||||||
</body>
|
|
||||||
</html>
|
|
|
@ -0,0 +1,143 @@
|
||||||
|
-- phpMyAdmin SQL Dump
|
||||||
|
-- version 5.2.1
|
||||||
|
-- https://www.phpmyadmin.net/
|
||||||
|
--
|
||||||
|
-- Host: 127.0.0.1
|
||||||
|
-- Generation Time: Paź 15, 2024 at 01:47 PM
|
||||||
|
-- Wersja serwera: 10.4.32-MariaDB
|
||||||
|
-- Wersja PHP: 8.2.12
|
||||||
|
|
||||||
|
SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
|
||||||
|
START TRANSACTION;
|
||||||
|
SET time_zone = "+00:00";
|
||||||
|
|
||||||
|
|
||||||
|
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
|
||||||
|
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
|
||||||
|
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
|
||||||
|
/*!40101 SET NAMES utf8mb4 */;
|
||||||
|
|
||||||
|
--
|
||||||
|
-- Database: `ocenienie`
|
||||||
|
--
|
||||||
|
|
||||||
|
-- --------------------------------------------------------
|
||||||
|
|
||||||
|
--
|
||||||
|
-- Struktura tabeli dla tabeli `kryterium`
|
||||||
|
--
|
||||||
|
|
||||||
|
CREATE TABLE `kryterium` (
|
||||||
|
`id_kryterium` int(11) NOT NULL,
|
||||||
|
`nazwa` varchar(255) NOT NULL,
|
||||||
|
`punkty` int(11) NOT NULL
|
||||||
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
|
||||||
|
|
||||||
|
--
|
||||||
|
-- Dumping data for table `kryterium`
|
||||||
|
--
|
||||||
|
|
||||||
|
INSERT INTO `kryterium` (`id_kryterium`, `nazwa`, `punkty`) VALUES
|
||||||
|
(1, 'Pomoc nauczycielowi', 10),
|
||||||
|
(2, 'Spóźnienie', -5),
|
||||||
|
(3, 'Przeszkadzanie', -10),
|
||||||
|
(4, 'Niewłaściwy stosunek do nauczycieli', -10),
|
||||||
|
(5, 'Palenie', -10),
|
||||||
|
(6, 'Udział w olimpiadzie', 20);
|
||||||
|
|
||||||
|
-- --------------------------------------------------------
|
||||||
|
|
||||||
|
--
|
||||||
|
-- Struktura tabeli dla tabeli `ocenazachowania`
|
||||||
|
--
|
||||||
|
|
||||||
|
CREATE TABLE `ocenazachowania` (
|
||||||
|
`id_oceny` int(11) NOT NULL,
|
||||||
|
`id_ucznia` int(11) DEFAULT NULL,
|
||||||
|
`id_kryterium` int(11) DEFAULT NULL,
|
||||||
|
`data` date DEFAULT NULL
|
||||||
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
|
||||||
|
|
||||||
|
-- --------------------------------------------------------
|
||||||
|
|
||||||
|
--
|
||||||
|
-- Struktura tabeli dla tabeli `uczen`
|
||||||
|
--
|
||||||
|
|
||||||
|
CREATE TABLE `uczen` (
|
||||||
|
`id_ucznia` int(11) NOT NULL,
|
||||||
|
`imie` varchar(255) NOT NULL,
|
||||||
|
`nazwisko` varchar(255) NOT NULL
|
||||||
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
|
||||||
|
|
||||||
|
--
|
||||||
|
-- Dumping data for table `uczen`
|
||||||
|
--
|
||||||
|
|
||||||
|
INSERT INTO `uczen` (`id_ucznia`, `imie`, `nazwisko`) VALUES
|
||||||
|
(1, 'Jan', 'Kowalski'),
|
||||||
|
(2, 'Anna', 'Nowak'),
|
||||||
|
(3, 'Piotr', 'Wiśniewski'),
|
||||||
|
(4, 'Katarzyna', 'Zielińska');
|
||||||
|
|
||||||
|
--
|
||||||
|
-- Indeksy dla zrzutów tabel
|
||||||
|
--
|
||||||
|
|
||||||
|
--
|
||||||
|
-- Indeksy dla tabeli `kryterium`
|
||||||
|
--
|
||||||
|
ALTER TABLE `kryterium`
|
||||||
|
ADD PRIMARY KEY (`id_kryterium`);
|
||||||
|
|
||||||
|
--
|
||||||
|
-- Indeksy dla tabeli `ocenazachowania`
|
||||||
|
--
|
||||||
|
ALTER TABLE `ocenazachowania`
|
||||||
|
ADD PRIMARY KEY (`id_oceny`),
|
||||||
|
ADD KEY `id_ucznia` (`id_ucznia`),
|
||||||
|
ADD KEY `id_kryterium` (`id_kryterium`);
|
||||||
|
|
||||||
|
--
|
||||||
|
-- Indeksy dla tabeli `uczen`
|
||||||
|
--
|
||||||
|
ALTER TABLE `uczen`
|
||||||
|
ADD PRIMARY KEY (`id_ucznia`);
|
||||||
|
|
||||||
|
--
|
||||||
|
-- AUTO_INCREMENT for dumped tables
|
||||||
|
--
|
||||||
|
|
||||||
|
--
|
||||||
|
-- AUTO_INCREMENT for table `kryterium`
|
||||||
|
--
|
||||||
|
ALTER TABLE `kryterium`
|
||||||
|
MODIFY `id_kryterium` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=7;
|
||||||
|
|
||||||
|
--
|
||||||
|
-- AUTO_INCREMENT for table `ocenazachowania`
|
||||||
|
--
|
||||||
|
ALTER TABLE `ocenazachowania`
|
||||||
|
MODIFY `id_oceny` int(11) NOT NULL AUTO_INCREMENT;
|
||||||
|
|
||||||
|
--
|
||||||
|
-- AUTO_INCREMENT for table `uczen`
|
||||||
|
--
|
||||||
|
ALTER TABLE `uczen`
|
||||||
|
MODIFY `id_ucznia` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=5;
|
||||||
|
|
||||||
|
--
|
||||||
|
-- Constraints for dumped tables
|
||||||
|
--
|
||||||
|
|
||||||
|
--
|
||||||
|
-- Constraints for table `ocenazachowania`
|
||||||
|
--
|
||||||
|
ALTER TABLE `ocenazachowania`
|
||||||
|
ADD CONSTRAINT `ocenazachowania_ibfk_1` FOREIGN KEY (`id_ucznia`) REFERENCES `uczen` (`id_ucznia`),
|
||||||
|
ADD CONSTRAINT `ocenazachowania_ibfk_2` FOREIGN KEY (`id_kryterium`) REFERENCES `kryterium` (`id_kryterium`);
|
||||||
|
COMMIT;
|
||||||
|
|
||||||
|
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
|
||||||
|
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
|
||||||
|
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
|
44
php.php
44
php.php
|
@ -1,44 +0,0 @@
|
||||||
<?php
|
|
||||||
$con = mysqli_connect('localhost', 'root', '', 'zdj2');
|
|
||||||
|
|
||||||
if($_SERVER['REQUEST_METHOD'] == 'POST'){
|
|
||||||
$data = json_decode(file_get_contents('php://input'), true);
|
|
||||||
$img = $data['zdj'];
|
|
||||||
$nazwa = $data['nazwa'];
|
|
||||||
|
|
||||||
$stmt = mysqli_prepare($con, 'INSERT INTO zdj(nazwa, zdj) VALUES (?, ?)');
|
|
||||||
mysqli_stmt_bind_param($stmt, 'ss', $nazwa, $img);
|
|
||||||
|
|
||||||
if(mysqli_stmt_execute($stmt)){
|
|
||||||
echo json_encode(['status'=>'wyslane']);
|
|
||||||
} else {
|
|
||||||
echo json_encode(['status'=>'blad']);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if($_SERVER['REQUEST_METHOD'] == "GET" && isset($_GET['type'])){
|
|
||||||
$ans = mysqli_query($con, "SELECT * FROM zdj");
|
|
||||||
$json = array();
|
|
||||||
while($row = mysqli_fetch_assoc($ans)){
|
|
||||||
$json[] = $row;
|
|
||||||
}
|
|
||||||
echo json_encode($json);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if($_SERVER['REQUEST_METHOD'] == 'GET' && isset($_GET["id"])){
|
|
||||||
$ans = mysqli_query($con, "SELECT zdj FROM zdj WHERE id = ". $_GET["id"]);
|
|
||||||
$json = array();
|
|
||||||
if($ans){
|
|
||||||
while($row = mysqli_fetch_assoc($ans)){
|
|
||||||
$json[] = $row;
|
|
||||||
}
|
|
||||||
echo json_encode($json);
|
|
||||||
} else {
|
|
||||||
echo json_encode(["status"=>"nie ma danych"]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
?>
|
|
60
script.js
60
script.js
|
@ -1,60 +0,0 @@
|
||||||
document.addEventListener('DOMContentLoaded', async ()=>{
|
|
||||||
const button = document.getElementById('submitZdj')
|
|
||||||
const selection = document.getElementById("wybor")
|
|
||||||
const img = document.getElementById('img')
|
|
||||||
|
|
||||||
let daneJson = await fetch('php.php?type=all')
|
|
||||||
if(!daneJson.ok){
|
|
||||||
throw new Error("Błąd połączenia")
|
|
||||||
}
|
|
||||||
let dane = await daneJson.json()
|
|
||||||
console.log(dane)
|
|
||||||
dane.forEach(opcja=>{
|
|
||||||
const option = document.createElement("option")
|
|
||||||
option.value = opcja.id
|
|
||||||
option.textContent = opcja.nazwa
|
|
||||||
selection.appendChild(option)
|
|
||||||
})
|
|
||||||
|
|
||||||
async function getBase64(file) {
|
|
||||||
return new Promise((resolve, reject) => {
|
|
||||||
const reader = new FileReader();
|
|
||||||
reader.readAsDataURL(file);
|
|
||||||
reader.onload = () => resolve(reader.result);
|
|
||||||
reader.onerror = error => reject(error);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
selection.addEventListener('change', async (event)=>{
|
|
||||||
let ansJson = await fetch('php.php?id=' + event.target.value)
|
|
||||||
let ans = await ansJson.json()
|
|
||||||
img.src = ans[0].zdj
|
|
||||||
console.log(ans)
|
|
||||||
})
|
|
||||||
|
|
||||||
button.addEventListener('click', async () =>{
|
|
||||||
const zdjInput = document.getElementById("zdjecie")
|
|
||||||
|
|
||||||
const zdj = zdjInput.files[0]
|
|
||||||
const data = {
|
|
||||||
zdj: await getBase64(zdj),
|
|
||||||
nazwa: zdj.name
|
|
||||||
}
|
|
||||||
console.log(data)
|
|
||||||
|
|
||||||
let fetchans = await fetch('php.php', {
|
|
||||||
method: 'POST',
|
|
||||||
headers: {
|
|
||||||
'Content-Type': 'application/json'
|
|
||||||
},
|
|
||||||
body: JSON.stringify(data)
|
|
||||||
})
|
|
||||||
|
|
||||||
if(!fetchans.ok){
|
|
||||||
throw new Error("Bład połączenia")
|
|
||||||
}
|
|
||||||
let ans = await fetchans.json()
|
|
||||||
console.log(ans)
|
|
||||||
})
|
|
||||||
|
|
||||||
})
|
|
Loading…
Reference in New Issue