1
0
Fork 0
This repository has been archived on 2024-02-17. You can view files and clone it, but cannot push or open issues or pull requests.
PHP_TP1/helloworld3.php
2020-10-01 08:41:35 +02:00

45 lines
1.1 KiB
PHP

<?php
$nb = null;
$name = null;
$error = false;
if (isset($_GET["nb"]) AND isset($_GET["name"])) {
$nb = (int)$_GET["nb"];
$name = htmlspecialchars($_GET["name"]);
if ($nb < 0 or $nb > 100) {
$error = true;
$nb = null;
$name = null;
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Hello World 3</title>
</head>
<body>
<form>
<label for="nb">Number: </label>
<input id="nb" type="number" name="nb" min="0" max="100" value="<?= $nb ?>" required>
<label for="name">Name: </label>
<input id="name" name="name" value="<?= $name ?>" required>
<input type="submit" value="Send">
</form>
<?php
if ($error) { ?>
<strong>Invalid args !</strong>
<?php } ?>
<ul>
<?php if ($nb !== null AND $name !== null) {
for ($i = 0; $i < $nb; $i++) { ?>
<li>Hello <?= $name ?> !</li>
<?php }
}?>
</ul>
</body>
</html>