200 lines
6.7 KiB
PHP
200 lines
6.7 KiB
PHP
<!DOCTYPE html>
|
|
<html lang="pl">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>GET, POST, if</title>
|
|
</head>
|
|
<body>
|
|
<h1>Pobieranie wartości z formularza, instrukcja warunkowa</h1>
|
|
<h2>1</h2>
|
|
<form action="./" method="post">
|
|
<input type="text" name="tekst1"><input type="submit" value="ok"><br>
|
|
<?= "wpisano: " . @$_POST['tekst1']?>
|
|
</form>
|
|
|
|
<h2>2</h2>
|
|
<form action="./wynik.php" method="post">
|
|
<h3>Ile masz lat</h3>
|
|
<input type="number" name="wiek" min="0" max="100" value="12">
|
|
<input type="submit" value="ok">
|
|
</form>
|
|
|
|
<h2>3</h2>
|
|
<form action="./" method="get">
|
|
<h3>Czy Impuls II to najlepszy EZT?</h3>
|
|
<select name="impuls">
|
|
<option value="t">tak</option>
|
|
<option value="n">nie</option>
|
|
</select>
|
|
<input type="submit" value="ok">
|
|
<?php
|
|
if(@$_GET['impuls'] == 't') {
|
|
echo '<p>Człowiek kultury.</p>';
|
|
} elseif(@$_GET['impuls'] == 'n') {
|
|
echo '<p>WTF?! Odpuszczę ci tylko gdy uważasz że Stadler FLIRT jest lepszy.</p>';
|
|
} else {
|
|
echo '<p>Hmmm?!</p>';
|
|
}
|
|
?>
|
|
</form>
|
|
|
|
<h2>4</h2>
|
|
<form action="./" method="post">
|
|
<input type="number" name="liczba1">
|
|
<select name="operacja">
|
|
<option><</option>
|
|
<option><=</option>
|
|
<option>=</option>
|
|
<option>>=</option>
|
|
<option>></option>
|
|
</select>
|
|
<input type="number" name="liczba2">
|
|
? <input type="submit" value="ok">
|
|
</form>
|
|
<?php
|
|
switch (@$_POST['operacja']) {
|
|
case '<':
|
|
if(@$_POST['liczba1'] < @$_POST['liczba2']) {
|
|
echo "<p>TAK</p>";
|
|
} else {
|
|
echo "<p>NIE</p>";
|
|
}
|
|
break;
|
|
case '<=':
|
|
if(@$_POST['liczba1'] <= @$_POST['liczba2']) {
|
|
echo "<p>TAK</p>";
|
|
} else {
|
|
echo "<p>NIE</p>";
|
|
}
|
|
break;
|
|
case '=':
|
|
if(@$_POST['liczba1'] == @$_POST['liczba2']) {
|
|
echo "<p>TAK</p>";
|
|
} else {
|
|
echo "<p>NIE</p>";
|
|
}
|
|
break;
|
|
case '>=':
|
|
if(@$_POST['liczba1'] >= @$_POST['liczba2']) {
|
|
echo "<p>TAK</p>";
|
|
} else {
|
|
echo "<p>NIE</p>";
|
|
}
|
|
break;
|
|
case '>':
|
|
if(@$_POST['liczba1'] > @$_POST['liczba2']) {
|
|
echo "<p>TAK</p>";
|
|
} else {
|
|
echo "<p>NIE</p>";
|
|
}
|
|
break;
|
|
}
|
|
?>
|
|
|
|
<h2>5</h2>
|
|
<form action="./" method="post">
|
|
<input type="number" name="_liczba1">
|
|
<select name="_operacja">
|
|
<option><</option>
|
|
<option><=</option>
|
|
<option>=</option>
|
|
<option>>=</option>
|
|
<option>></option>
|
|
</select>
|
|
<input type="number" name="_liczba2">
|
|
? <input type="image" alt="ok" width="40px" src="https://img.freepik.com/premium-wektory/znak-ok-z-ikona-symbolu-reki_423491-228.jpg?semt=ais_hybrid&w=740&q=80">
|
|
</form>
|
|
<?php
|
|
switch (@$_POST['_operacja']) {
|
|
case '<':
|
|
if(@$_POST['_liczba1'] < @$_POST['_liczba2']) {
|
|
echo "<p>TAK</p>";
|
|
} else {
|
|
echo "<p>NIE</p>";
|
|
}
|
|
break;
|
|
case '<=':
|
|
if(@$_POST['_liczba1'] <= @$_POST['_liczba2']) {
|
|
echo "<p>TAK</p>";
|
|
} else {
|
|
echo "<p>NIE</p>";
|
|
}
|
|
break;
|
|
case '=':
|
|
if(@$_POST['_liczba1'] == @$_POST['_liczba2']) {
|
|
echo "<p>TAK</p>";
|
|
} else {
|
|
echo "<p>NIE</p>";
|
|
}
|
|
break;
|
|
case '>=':
|
|
if(@$_POST['_liczba1'] >= @$_POST['_liczba2']) {
|
|
echo "<p>TAK</p>";
|
|
} else {
|
|
echo "<p>NIE</p>";
|
|
}
|
|
break;
|
|
case '>':
|
|
if(@$_POST['_liczba1'] > @$_POST['_liczba2']) {
|
|
echo "<p>TAK</p>";
|
|
} else {
|
|
echo "<p>NIE</p>";
|
|
}
|
|
break;
|
|
}
|
|
?>
|
|
|
|
<h2>6</h2>
|
|
<form action="./" method="post">
|
|
<h3>Wpisz współczynniki równania kwadratowego</h3>
|
|
<input type="number" name="a">x<sup>2</sup>+
|
|
<input type="number" name="b">x+
|
|
<input type="number" name="c">=0
|
|
<input type="submit" value="oblicz pierwiastki">
|
|
</form>
|
|
<?php
|
|
if(isset($_POST['a']) && isset($_POST['b']) && isset($_POST['c'])) {
|
|
$delta=($_POST['b'] ** 2) - (4 * $_POST['a'] * $_POST['c']);
|
|
echo "delta=$delta<br>";
|
|
if($delta < 0) {
|
|
echo "brak pierwiastkow";
|
|
} elseif($delta == 0) {
|
|
$x0=(-$_POST['b'])/(2*$_POST['a']);
|
|
echo "x<sub>0</sub>=$x0";
|
|
} else {
|
|
$x1=(-$_POST['b']-sqrt($delta))/(2*$_POST['a']);
|
|
$x2=(-$_POST['b']+sqrt($delta))/(2*$_POST['a']);
|
|
echo "x<sub>1</sub>=$x1<br>x<sub>2</sub>=$x2";
|
|
}
|
|
}
|
|
?>
|
|
|
|
<h2>7</h2>
|
|
<form action="./" method="post">
|
|
<h3>Wpisz współczynniki równania kwadratowego</h3>
|
|
<input type="number" name="_a">x<sup>2</sup>+
|
|
<input type="number" name="_b">x+
|
|
<input type="number" name="_c">=0
|
|
<input type="submit" value="oblicz pierwiastki"><br><br>
|
|
</form>
|
|
<?php
|
|
if(isset($_POST['_a']) && isset($_POST['_b']) && isset($_POST['_c'])) {
|
|
$delta=($_POST['_b'] ** 2) - (4 * $_POST['_a'] * $_POST['_c']);
|
|
echo "Δ=<input style='color: red;' size=1 disabled value='$delta'> ";
|
|
if($delta < 0) {
|
|
echo "brak pierwiastkow";
|
|
} elseif($delta == 0) {
|
|
$x0=(-$_POST['_b'])/(2*$_POST['_a']);
|
|
echo "x<sub>0</sub>=<input style='color: green;' disabled value='$x0'>";
|
|
} else {
|
|
$x1=(-$_POST['_b']-sqrt($delta))/(2*$_POST['_a']);
|
|
$x2=(-$_POST['_b']+sqrt($delta))/(2*$_POST['_a']);
|
|
echo "x<sub>1</sub>=<input style='color: green;' disabled value='$x1'> x<sub>2</sub>=<input style='color: green;' disabled value='$x2'>";
|
|
}
|
|
}
|
|
?>
|
|
|
|
</body>
|
|
</html>
|