Show sourcecode
The following files exists in this folder. Click to view.
webbserverprogrammering/exercises/repetition/
repetiotion5b.php
41 lines UTF-8 Windows (CRLF)
<?php
error_reporting(-1);
ini_set('display_errors', 1);
ini_set('output_buffering', 0);
?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Rep 5b</title>
</head>
<body>
Gissa på eTt taL MELLAN noll OCH 10!
<form method="post" action="">
<input type="text" name="skickat">
<input type="submit" value="Skicka"><br>
<?php
$antal = 0;
if (isset($_POST["skickat"]) && $_POST["skickat"] !="") {
$namn = $_POST["namn"];
$slumpTal = $_POST["talet"];
$antal = $_POST["antal"]+1;
$mottaget = $_POST["skickat"];
echo "Hej $namn !";
echo "<p>Du gissade: ".$mottaget."</p>";
if ( $mottaget == $slumpTal ) echo "<p>RÄTT!</p>";
else echo "<p>Tyvärr fel, testa igen!</p>";
echo "<input type='hidden' name='namn' value='$namn'>";
echo "<input type='hidden' name='antal' value='$antal'>";
}
else {
echo "<p>Hej vad heter du?<br><input type='text' name='namn'></p>";
$slumpTal = random_int(0, 10);
}
?>
Du har gissat <?=$antal?> gånger
<input type="hidden" name="talet" value="<?=$slumpTal?>">
</form>
</body>
</html>