Files
2p_pracownia_programowania_php/Zadania/Z64 - dni w miesiącu i luty/index.php
2025-10-15 09:28:40 +02:00

52 lines
1.5 KiB
PHP

<?php
$html = "";
if(isset($_POST['miesiac']) && isset($_POST['rok'])) {
$miesiac = $_POST['miesiac'];
$rok = $_POST['rok'];
$dni = 31;
if($miesiac == 2) {
if($rok % 4 == 0)
$dni = 29;
else
$dni = 28;
} else if ($miesiac == 4 || $miesiac == 6 || $miesiac == 9 || $miesiac == 11) {
$dni = 30;
}
$html = "<div class='box'><p>Miesiąc numer $miesiac ma <b>$dni</b> dni</p></div>";
}
echo <<<HTML
<!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>Z64 - dni w miesiącu i luty</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<header>
<h1>Zadanie Z64</h1>
<h2>Autor: Jakub Grzegorczyk</h2>
</header>
<div class="box">
<p>Napisz program, który jak poprzednio, ale w przypadku lutego pyta dodatkowo o rok i dla lat przestępnych wyświetla 29 dni, a dla pozostałych 28.</p>
</div>
<div class="box">
<form action="index.php" method="post">
<label for="miesiac">Podaj numer miesiąca (1 - 12): </label> <br>
<input type="number" name="miesiac" id="miesiac"> <br>
<label for="rok">Podaj rok: </label> <br>
<input type="number" name="rok" id="rok"> <br>
<button type="submit">Sprawdź</button>
</form>
</div>
{$html}
</body>
</html>
HTML;