This commit is contained in:
3p01
2025-10-16 12:23:45 +02:00
parent 5d13103032
commit f8ec0df47f
2 changed files with 127 additions and 0 deletions

View File

@@ -0,0 +1,59 @@
<?php
$do_bazy = new mysqli('localhost', 'root', '', '3p1_biblioteka');
if ($do_bazy -> connect_error) {
exit("Błąd połączenia z serwerem MySQL.");
}
?>
<!doctype html>
<html lang="pl">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>T62 - Zastosowanie biblioteki PDO</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<header>
<h1>Zadanie T62</h1>
<h2>Autor: Jakub Grzegorczyk</h2>
</header>
<div class="box">
<p>
<b>Ćwiczenie 6.31 - ćwiczenie z podręcznika</b><br>
Utwórz podobnie jak w ćwiczeniu 6.29 (z podręcznika) skrypt, który dane pobrane z formularza będzie dodawał w bazie 3p1_biblioteka (zaimportuj ją z załączonego pliku biblioteka.sql) do tabeli autorzy. W skrypcie zastosuj polecenia mysqli zorientowanego obiektowo.
</p>
</div>
<div class="box">
<form action="index.php" method="post">
<p id="wyb">Rejestracja autora:</p>
<label for="imie">Imię:</label><br>
<input type="text" name="imie" id="imie" required><br>
<label for="nazwisko">Nazwisko: </label><br>
<input type="text" name="nazwisko" id="nazwisko" required>
<p><input type="submit" value="Wyślij" name="wyslij">
<input type="reset" value="Wyczyść" name="zeruj"></p>
</form>
</div>
<?php
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$nazwisko = $_POST['nazwisko'];
$imie = $_POST['imie'];
$dodaj = "INSERT INTO autorzy VALUES ('', '$imie', '$nazwisko')";
$zapytanie = $do_bazy -> query($dodaj);
echo "<div class='box'> <p>";
if (!$zapytanie === true) {
echo"Nowy autor nie został dodany do bazy!";
} else {
echo"Autor ".$imie . " " .$nazwisko. " został dodany do bazy.";
}
echo "</p></div>";
$do_bazy -> close();
}
?>
</body>
</html>

View File

@@ -0,0 +1,68 @@
* {
box-sizing: border-box;
}
body {
font-family: Verdana, serif;
background: #ffffff;
margin: 15px;
font-size: 0.9em;
}
header {
border: 2px solid black;
border-radius: 1em;
padding: 10px 20px;
box-shadow: rgba(0, 0, 0, 0.2) 3px 3px 5px;
background: #f0f0f0;
}
input {
margin-top: 5px;
margin-bottom: 5px;
width: 30%;
border: black 2px solid;
border-radius: 0.5em;
height: 2em;
}
button {
padding: 5px;
width: 30%;
border: black 2px solid;
border-radius: 0.5em;
font-weight: bold;
margin-top: 10px;
}
pre {
font-family: Verdana, serif;
}
.box {
border: 2px solid black;
padding: 15px 20px;
border-radius: 1em;
margin: 15px 0 10px 0;
box-shadow: rgba(0, 0, 0, 0.2) 3px 3px 5px;
}
.box h3 {
cursor: pointer;
}
td {
width: 50px;
height: 50px;
margin: 0;
padding: 0;
}
tr {
padding: 0;
}
.y {
background: yellow;
}
.b {
background:blue;
}