Browse Source

02 doucko

master
KubMakCZ 1 year ago
parent
commit
7306208d69
  1. 22
      02/formular.php
  2. 30
      02/formular_post.php
  3. 26
      02/index.php
  4. 10
      02/post_welcome.php
  5. 29
      02/prace.php
  6. 3
      02/tester.php
  7. 2
      README.md

22
02/formular.php

@ -0,0 +1,22 @@
<!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>
<form action="formular_post.php" method="post">
<label for="name">name:</label>
<input type="text" name="name" id="name">
<br>
<label for="email">email:</label>
<input type="email" name="email" id="email">
<br>
<label for="text">text:</label>
<input type="text" name="text" id="text">
<br>
<input type="submit" value="Save to book">
</form>
</body>
</html>

30
02/formular_post.php

@ -0,0 +1,30 @@
<?php
$name = $_POST["name"];
$email = $_POST["email"];
$text = $_POST["text"];
$servername = "localhost";
$username = "root";
$password = "toor";
$dbname = "wtl";
// Create connection
$conn = mysqli_connect($servername, $username, $password, $dbname);
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
$sql = "INSERT INTO kniha (name, email, text)
VALUES ('$name', '$email', '$text')";
echo $sql;
if (mysqli_query($conn, $sql)) {
echo "New record created successfully";
header('Location: http://localhost/prace.php');
} else {
echo "Error: " . $sql . "<br>" . mysqli_error($conn);
}
mysqli_close($conn);
?>

26
02/index.php

@ -0,0 +1,26 @@
<!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>
<h1>Pozdrav z HTML</h1>
<?php echo "<h2> pozdrav z PHP </h2>"; ?>
<form action="post_welcome.php" method="post">
<label for="name">name:</label>
<input type="text" name="name" id="name">
<br>
<label for="mail">Email</label>
<input type="email" name="mail" id="mail">
<br>
<input type="submit" value="SEND">
</form>
<hr>
<a href="prace.php">PRACE S DATABSAZIIIIII</a>
</body>
</html>

10
02/post_welcome.php

@ -0,0 +1,10 @@
<?php
// echo var_dump($_POST);
$name = $_POST["name"];
$mail = $_POST["mail"];
echo "Hello " . $name . ". We send email at ". $mail . " very soon. ☺";
echo "<br>";
echo '<a href="/"> HOME </a>';
?>

29
02/prace.php

@ -0,0 +1,29 @@
<?php
$servername = "localhost";
$username = "root";
$password = "toor";
$dbname = "wtl";
// Create connection
$conn = mysqli_connect($servername, $username, $password, $dbname);
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
$sql = "SELECT * FROM kniha";
$result = mysqli_query($conn, $sql);
if (mysqli_num_rows($result) > 0) {
while($row = mysqli_fetch_assoc($result)) {
echo "<p> id: <b>" . $row["id"] . "</b>";
echo " name: <b>" . $row["name"] . "</b>";
echo " email: <b>" . $row["email"] . "</b>";
echo " text: <b>" . $row["text"] . "</b>";
echo "</p>";
}
} else {
echo "0 results";
}
?>

3
02/tester.php

@ -0,0 +1,3 @@
<?php
echo "My first PHP script!";
?>

2
README.md

@ -0,0 +1,2 @@
# Doučování WTL
Loading…
Cancel
Save