Webbserverprogrammering 1

Show sourcecode

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

ramverket/exercises/formular/

ovn_form1-1.php
ovn_form1-2.php
ovn_form2-1.php
ovn_form2-2.php
ovn_form3-1.php
ovn_form3-2.php
ovn_form4-1.php
ovn_form4-2.php
ovn_form5-1.php
ovn_form5-2.php
ovn_form6-1.php
ovn_form6-2.php
ovn_form7-1.php
ovn_form7-2.php
ovn_form8.php

ovn_form6-2.php

49 lines UTF-8 Windows (CRLF)
<?php
  
// Title: Formulär 6
  
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="sv">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Formulär 6</title>
</head>
<body>
  <?php
    $first_name 
$_POST['first_name'];
    
$last_name $_POST['last_name'];
    
$class $_POST['class'];
    
$food $_POST['food'];
    
$subject $_POST['subject'];

    function 
format_string($food) {
      
$food_string "";
      for (
$i 0$i count($food); $i++) {
        if (
$i == count($food) - 1) {
          
$food_string .= $food[$i];
          continue;
        }
        
$food_string .= $food[$i] . ", ";
      }
      return 
$food_string;
    }

    if (!
$food) {
      
$string "Hej $first_name $last_name i $class! Du har inga favoritmaträtter! Din favoritkurs är $subject.";
    } else if (
count($food) == 1) {
      
$food_string $food[0];
      
$string "Hej $first_name $last_name i $class! Din favoritmaträtt är $food_string! Din favoritkurs är $subject.";
    } else if (
count($food) > 1) {
      
$food_string format_string($food);
      
$string "Hej $first_name $last_name i $class! Dina favoritmaträtter är $food_string! Din favoritkurs är $subject.";
    }

    echo 
htmlspecialchars($string);
    
mail("pavvor23@varmdogymnasium.se""Formulär 6"htmlspecialchars($string));
  
?>
</body>
</html>