Webbserverprogrammering 1

Show sourcecode

The following files exists in this folder. Click to view.

webbsrvprg/exercises/ovning6/

index.html
ovn_frmt3.php
ovn_frmt6.php
test.html

ovn_frmt3.php

116 lines UTF-8 Windows (CRLF)
<?php
error_reporting
(-1); // Report all type of errors
ini_set('display_errors'1); // Display all errors 
ini_set('output_buffering'0); // Do not buffer outputs, write directly
?>
<!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 method="post" action="">
        <?php if(count($_POST) == 0) { ?>
            <label for="name">Namn</label><br>
            <input type="text" name="name"> <br>
            <input type="submit" value="Skicka">
        <?php } if(count($_POST) == 1) {?>
        <fieldset>
            <legend>Vem är bästa fotbollspelaren någonsin?</legend>
            <div>
                <input type="radio" name="fraga1" value="Messi" id="">
                <label for="Messi">Lionel Andrés Messi</label>
            </div>
            <div>
                <input type="radio" name="fraga1" value="Penaldo" id="">
                <label for="Penaldo">Cristiano Penaldo</label>
            </div>
            <div>
                <input type="radio" name="fraga1" value="Akinfenwa" id="">
                <label for="Akinfenwa">Adebayo Akinfenwa</label>
            </div>
            <div>
                <input type="radio" name="fraga1" value="Lamine" id="">
                <label for="Lamine">Lamine Yamal</label>
            </div>
            <input type="hidden" name="name" value="<?php echo $_POST["name"]; ?>">
            <input type="submit" value="Skicka">
        </fieldset>
        <?php } if(count($_POST) == 2) {?>
        <fieldset id="fraga2">
            <legend>Vilket lag har flest CL-titlar?</legend>
            <div>
                <input type="radio" name="fraga2" value="FCB" id="">
                <label for="FCB">FC Barcelona</label>
            </div>
            <div>
                <input type="radio" name="fraga2" value="Milan" id="">
                <label for="Milan">AC Milan</label>
            </div>
            <div>
                <input type="radio" name="fraga2" value="Real" id="">
                <label for="Real">Real Madrid</label>
            </div>
            <div>
                <input type="radio" name="fraga2" value="City" id="">
                <label for="City">Manchester City</label>
            </div>
            <input type="hidden" name="name" value="<?php echo $_POST["name"]; ?>">
            <input type="hidden" name="fraga1" value="<?php echo $_POST["fraga1"]; ?>">
            <input type="submit" value="Skicka">
        </fieldset>
        <?php } if(count($_POST) == 3) {?>
        <fieldset id="fraga3">
            <legend>Vilket lag vann EM 2024?</legend>
            <div>
                <input type="radio" name="fraga3" value="England" id="">
                <label for="England">England</label>
            </div>
            <div>
                <input type="radio" name="fraga3" value="Frankrike" id="">
                <label for="Frankrike">Frankrike</label>
            </div>
            <div>
                <input type="radio" name="fraga3" value="Neder" id="">
                <label for="Neder">Nederländerna</label>
            </div>
            <div>
                <input type="radio" name="fraga3" value="Spanien" id="">
                <label for="Spanien">Spanien</label>
            </div>
            <input type="hidden" name="name" value="<?php echo $_POST["name"]; ?>">
            <input type="hidden" name="fraga1" value="<?php echo $_POST["fraga1"]; ?>">
            <input type="hidden" name="fraga2" value="<?php echo $_POST["fraga2"]; ?>">
        <input type="submit" value="Skicka">
        </fieldset>
        <?php }?>
        <br>
    </form>
    <?php
    
if (count($_POST) == 4) {
        
$namn $_POST["name"];
        
$svar1 $_POST["fraga1"];
        
$svar2 $_POST["fraga2"];
        
$svar3 $_POST["fraga3"];
        
$antalRatt 0;
        if(
$svar1 == "Messi"){
            
$antalRatt += 1;
        }
        if(
$svar2 == "Real"){
            
$antalRatt += 1;
        }
        if(
$svar3 == "Spanien"){
            
$antalRatt += 1;
        }
        echo 
"Hej "$namn"! <br>";
        echo 
"Du hade "$antalRatt" av 3 rätt";

    }
    
?>
</body>

</html>