Geizkragen/wunschliste.php

78 lines
2.2 KiB
PHP

<?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
if (!isset($_SESSION['user_id'])) {
header("Location: login.php");
exit();
}
?>
<?php
$stmt = $conn->prepare("
SELECT products.productID, products.model, products.description, products.imagePath
FROM userFavorites INNER JOIN products ON userFavorites.productID = products.productID
WHERE userID = ?
");
$stmt->bind_param("i", $_SESSION['user_id']);
$stmt->execute();
$result = $stmt->get_result();
?>
<?php if ($result->num_rows > 0): ?>
<section class="product-section">
<div class="product-scroll">
<?php while ($product = $result->fetch_assoc()): ?>
<?php $productId = (int)$product['productID']; ?>
<a class="product-card" href="productpage.php?id=<?= $productId ?>">
<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>
</a>
<?php endwhile; ?>
</div>
</section>
<?php endif; ?>
<?php $stmt->close(); ?>
<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'; ?>