<?php

error_reporting(E_ALL);
ini_set('display_errors', 1);

$host = "192.168.1.20";
$database = "orologi";
$user = "pdo";
$password = "";

try {
    $connection = new PDO("mysql:host=$host;dbname=$database", $user, $password);

    $prepare = $connection->prepare("SELECT * FROM orologi WHERE Codice = ?");
    $prepare->bindValue(1, $_GET["cod"], PDO::PARAM_INT);
    $prepare->execute();

    if ($prepare->rowCount() == 0) {
        die("Non trovato");
    }
    $connection = null;

} catch (PDOException $e) {
    die ("Error!: " . $e->getMessage() . "<br/>");
}

?>

<html lang="en">
<head>
    <title>HTML</title>
    <link
            rel="stylesheet"
            href="https://cdn.jsdelivr.net/npm/@picocss/pico@2/css/pico.min.css"
    >
</head>

<body>
    <main class="container">
        <nav>
            <ul>
                <li><strong>Acme Corp</strong></li>
            </ul>
            <ul>
                <li><a href="index.php">Home</a></li>
                <li><a href="#">Login</a></li>
            </ul>
        </nav>
        <?php foreach ($prepare->fetchAll() as $row) : ?>
            <h1><?= $row["Marca"] . " " . $row["Modello"] ?></h1>
            <h2>Descrizione</h2>
            <p><?= $row["Descrizione"] ?></p>
            <h2>Prezzo: <?= $row["Prezzo"] ?> &euro;</h2>
            <p><small>(Codice Orologio: <?= $row["Codice"] ?>)</p>
        <?php endforeach; ?>
    </main>
</body>

</html>