<?php include 'header.php'; ?>

<?php
// login.php

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

session_start();

// 1) DB-Verbindung (einmal)
$servername = "localhost";
$port = 3306;
$username = "FSST";
$password = "L9wUNZZ9Qkbt";
$db = "FSST";

$conn = mysqli_connect($servername, $username, $password, $db, $port);
if (!$conn)
{
    http_response_code(500);
    die("Datenbankfehler");
}
?>

<?php
$productId = isset($_GET['id']) ? (int)$_GET['id'] : 0;
?>

<?php if ($productId <= 0): ?>
    <section class="product-section">
        <h2>Produkt nicht gefunden</h2>
        <p>Bitte eine gueltige Produkt-ID mitgeben.</p>
    </section>
<?php else: ?>
    <?php
    $stmt = $conn->prepare("
        SELECT productID, model, description, imagePath
        FROM products
        WHERE productID = ?
        LIMIT 1
    ");

    $stmt->bind_param("i", $productId);
    $stmt->execute();

    $result = $stmt->get_result();
    $product = $result->fetch_assoc();
    ?>

    <?php if ($product): ?>
        <section class="product-section">
            <div class="product-scroll">
                <div class="product-card">
                    <img
                        src="<?= isset($product['imagePath']) ? $product['imagePath'] : 'assets/images/placeholder.png' ?>"
                        alt="<?= htmlspecialchars($product['model']) ?>">

                    <div class="product-card__content">
                        <h3><?= htmlspecialchars($product['model']) ?></h3>
                        <p><?= htmlspecialchars($product['description']) ?></p>
                    </div>
                </div>
            </div>
        </section>
    <?php else: ?>
        <section class="product-section">
            <h2>Produkt nicht gefunden</h2>
            <p>Zu dieser ID gibt es kein Produkt.</p>
        </section>
    <?php endif; ?>

    <?php $stmt->close(); ?>
<?php endif; ?>



<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <link rel="stylesheet" href="assets/css/compcard.css">
</head>

<?php include 'footer.php'; ?>