<?php
// ===== 1. PRÁCTICA CICLO FOR =====
echo "<h3>Ciclo for</h3>";
for ($i = 1; $i <= 10; $i++) {
    echo "7 x $i = " . (7 * $i) . "<br>";
}

$suma = 0;
for ($n = 1; $n <= 100; $n++) {
    $suma += $n;
}
echo "Suma de 1 a 100: $suma<br>";

// ===== 2. PRÁCTICA SWITCH / CASE =====
echo "<h3>Sentencia switch</h3>";
$dia = "martes";
switch ($dia) {
    case "lunes":
        echo "Inicio de semana"; break;
    case "martes":
    case "miércoles":
    case "jueves":
        echo "Entre semana"; break;
    case "viernes":
        echo "¡Por fin viernes!"; break;
    case "sábado":
    case "domingo":
        echo "Fin de semana"; break;
    default:
        echo "Día no válido";
}
echo "<hr>";

// ===== 3. FORMULARIO RESTAURANTE + REGISTRO DE MENÚ =====
if ($_SERVER["REQUEST_METHOD"] === "POST") {
    $platillo    = htmlspecialchars(trim($_POST["platillo"] ?? ""));
    $categoria   = htmlspecialchars($_POST["categoria"] ?? "");
    $descripcion = htmlspecialchars(trim($_POST["descripcion"] ?? ""));
    $precio      = floatval($_POST["precio"] ?? 0);

    $errores = [];
    if ($platillo === "")  $errores[] = "Falta el nombre del platillo.";
    if ($categoria === "") $errores[] = "Selecciona una categoría.";
    if ($precio <= 0)      $errores[] = "El precio debe ser mayor a cero.";

    if ($errores) {
        foreach ($errores as $e) echo "<p style='color:red'>$e</p>";
    } else {
        switch ($categoria) {
            case "Entrada":      $tipo = "Para empezar"; break;
            case "Plato fuerte": $tipo = "Plato principal"; break;
            case "Postre":       $tipo = "Dulce final"; break;
            case "Bebida":       $tipo = "Para acompañar"; break;
            default:             $tipo = "Sin clasificar";
        }

        $linea = "$platillo | $categoria | $tipo | $" . number_format($precio, 2)
               . " | $descripcion | " . date("d/m/Y H:i") . PHP_EOL;
        file_put_contents("menu.txt", $linea, FILE_APPEND | LOCK_EX);

        echo "<h3>Platillo registrado</h3>";
        echo "<p><strong>$platillo</strong> ($tipo) — $" . number_format($precio, 2) . "</p>";
        echo "<p>$descripcion</p>";
    }
}
?>
<!DOCTYPE html>
<html lang="es">
<head><meta charset="UTF-8"><title>Registro de menú</title></head>
<body>
<h3>Registrar platillo</h3>
<form method="POST" action="">
    <label>Nombre del platillo:</label><br>
    <input type="text" name="platillo" required><br><br>

    <label>Categoría:</label><br>
    <select name="categoria" required>
        <option value="">-- Selecciona --</option>
        <option value="Entrada">Entrada</option>
        <option value="Plato fuerte">Plato fuerte</option>
        <option value="Postre">Postre</option>
        <option value="Bebida">Bebida</option>
    </select><br><br>

    <label>Precio:</label><br>
    <input type="number" name="precio" step="0.01" min="0" required><br><br>

    <label>Descripción:</label><br>
    <textarea name="descripcion" rows="3"></textarea><br><br>

    <button type="submit">Guardar platillo</button>
</form>
</body>
</html>

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: