107 funkce + formulář required

This commit is contained in:
kankys 2024-09-30 17:49:39 +02:00
parent 6f18eb5bfb
commit 06061f84dc
6 changed files with 60 additions and 15 deletions

View File

@ -1,12 +1,24 @@
<?php
$db_host = "127.0.0.1";
$db_user = "kankys.jr";
$db_password = "Heslo123";
$db_name = "skola";
/**
* Připojení se k databázi
*
* @return object - připojení k databázi
*
*/
function connectionDB() {
$db_host = "127.0.0.1";
$db_user = "kankys.jr";
$db_password = "Heslo123";
$db_name = "skola";
$connection = mysqli_connect($db_host, $db_user, $db_password, $db_name);
if (mysqli_connect_error()) {
$connection = mysqli_connect($db_host, $db_user, $db_password, $db_name);
if (mysqli_connect_error()) {
echo mysqli_connect_error();
exit();
}
return $connection;
}
?>

View File

@ -0,0 +1,3 @@
<footer>
<p>&copy; Škola čar a kouzel v Bradavicích, Lukáš Kaňka, 2024</p>
</footer>

View File

@ -1,7 +1,10 @@
<?php
global $connection;
require "assets/database.php";
$connection = connectionDB();
if (isset($_GET["id"]) and is_numeric($_GET["id"])) {
$sql = "SELECT * FROM student WHERE id = ". $_GET["id"];

View File

@ -2,14 +2,18 @@
global $connection;
require "assets/database.php";
if ($_SERVER ["REQUEST_METHOD"] === "POST") {
require "assets/database.php";
$sgl = "INSERT INTO student (first_name, second_name, age, life, college)
VALUES (?, ?, ?, ?, ?)";
$connection = connectionDB();
$statement = mysqli_prepare($connection, $sgl);
if ($statement === false) {
@ -40,15 +44,15 @@ if ($_SERVER ["REQUEST_METHOD"] === "POST") {
<main>
<section class="add-form">
<form action="pridat-zaka.php" method="POST">
<input type="text" name="first_name" placeholder="Křestní jméno">
<input type="text" name="first_name" placeholder="Křestní jméno" required>
<br>
<input type="text" name="second_name" placeholder="Příjmení">
<input type="text" name="second_name" placeholder="Příjmení" required>
<br>
<input type="number" name="age" placeholder="Věk" min="10">
<input type="number" name="age" placeholder="Věk" min="10" required>
<br>
<textarea name="life" placeholder="Podrobnosti o žákovi"></textarea>
<textarea name="life" placeholder="Podrobnosti o žákovi" required></textarea>
<br>
<input type="text" name="college" placeholder="Kolej">
<input type="text" name="college" placeholder="Kolej" required>
<br>
<input type="submit" value="Přidat žáka">
</form>

View File

@ -0,0 +1,21 @@
<?php
/**
* Popis studenta
*
* @param string $first_name - křestní jméno studenta
* @param string $second_name - příjmení studenta
* @param int $age - věk studenta
*
* @return string popis studenta
*/
function studentDescription($first_name, $second_name, $age){
return "Toto je " . $first_name . " " . $second_name . ".
Věk studenta je " . $age . " let. <br>";
}
// Použití
echo studentDescription("Harry", "Potter", 15);
echo studentDescription("Ron", "Weasley", 14);
$student = studentDescription("Hermiona", "Grangerová", 15);
echo $student;

View File

@ -4,6 +4,8 @@ require "assets/database.php";
$sql = "SELECT * FROM student";
$connection = connectionDB();
$result = mysqli_query($connection, $sql);
if ($result === false) {