Úspěšné create database
This commit is contained in:
parent
8bea73bdd6
commit
5721707bda
12
www2databaze/database.php
Normal file
12
www2databaze/database.php
Normal file
@ -0,0 +1,12 @@
|
||||
<?php
|
||||
$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()) {
|
||||
echo mysqli_connect_error();
|
||||
exit();
|
||||
}
|
||||
?>
|
49
www2databaze/jeden-zak.php
Normal file
49
www2databaze/jeden-zak.php
Normal file
@ -0,0 +1,49 @@
|
||||
<?php
|
||||
global $connection;
|
||||
require "database.php";
|
||||
|
||||
if (isset($_GET["id"]) and is_numeric($_GET["id"])) {
|
||||
$sql = "SELECT * FROM student WHERE id = ". $_GET["id"];
|
||||
|
||||
$result = mysqli_query($connection, $sql);
|
||||
if ($result === false) {
|
||||
echo mysgli_error($connection);
|
||||
} else {
|
||||
$students = mysqli_fetch_assoc($result);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
?>
|
||||
|
||||
<!DOCTYPE html>
|
||||
<html lang="cs">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Document</title>
|
||||
</head>
|
||||
<body>
|
||||
<header>
|
||||
<h1>Informace o žákovi</h1>
|
||||
</header>
|
||||
|
||||
<main>
|
||||
<section>
|
||||
<?php if ($students === null): ?>
|
||||
<p>Žák nenalezen</p>
|
||||
<?php else : ?>
|
||||
<h2><?php echo $students["first_name"]. " " .$students["second_name"] ?></h2>
|
||||
<p>Věk: <?php echo $students["age"] ?></p>
|
||||
<p>Dodatečné informace: <?= $students["life"] ?></p>
|
||||
<p>Kolej: <?= $students["collage"] ?></p>
|
||||
<?php endif ?>
|
||||
</section>
|
||||
</main>
|
||||
|
||||
<footer>
|
||||
|
||||
</footer>
|
||||
</body>
|
||||
</html>
|
@ -1,23 +1,19 @@
|
||||
<?php
|
||||
$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()) {
|
||||
echo mysqli_connect_error();
|
||||
exit();
|
||||
}
|
||||
|
||||
//echo "Úspěšné přihlášení do databáze";
|
||||
global $connection;
|
||||
require "database.php";
|
||||
|
||||
$sql = "SELECT * FROM student";
|
||||
//echo "<br>";
|
||||
|
||||
$result = mysqli_query($connection, $sql);
|
||||
//var_dump($result);
|
||||
//echo "<br>";
|
||||
|
||||
if ($result === false) {
|
||||
echo mysgli_error($connection);
|
||||
} else {
|
||||
$students = mysqli_fetch_all($result, MYSQLI_ASSOC);
|
||||
}
|
||||
|
||||
|
||||
|
||||
//var_dump($students);
|
||||
|
||||
?>
|
||||
@ -41,6 +37,7 @@ $students = mysqli_fetch_all($result, MYSQLI_ASSOC);
|
||||
<ul>
|
||||
<?php foreach ($students as $one_student): ?>
|
||||
<li><?php echo $one_student["first_name"]. " " .$one_student["second_name"] ?></li>
|
||||
<a href="jeden-zak.php?id=<?= $one_student['id'] ?>">Více informací</a>
|
||||
<?php endforeach; ?>
|
||||
|
||||
</ul>
|
||||
|
Loading…
Reference in New Issue
Block a user