wunschliste.php modified that only products in database userFavorites are monitored. Problem with Wunschlisten Add button fixed. !!! Not possible yet: deleting things from wishlist !!!

This commit is contained in:
Paul Eisenbock 2026-02-21 17:27:52 +01:00
parent 73b7ff1baf
commit 1ad4d05473
4 changed files with 57 additions and 44 deletions

View File

@ -125,9 +125,8 @@ S
.shop-left {
display: flex;
align-items: center;
gap: 16px;
gap: 28px; /* vorher ~18px */
}
.shop-logo {
display: flex;
align-items: center;
@ -152,12 +151,13 @@ S
}
.shop-middle {
display: flex; /* statt column */
display: flex;
align-items: center;
gap: 30px; /* Abstand zwischen Preis / Versand / Lager */
color: #cbd5e1;
gap: 55px; /* vorher ~35px → jetzt deutlich mehr Abstand */
font-size: 14px;
color: #cbd5e1;
}
.shop-shipping {
display: flex;
flex-direction: column;
@ -184,6 +184,7 @@ S
}
.shop-price {
margin-left: auto;
font-size: 18px; /* kleiner als vorher */
font-weight: 700;
color: #4ade80;

Binary file not shown.

After

Width:  |  Height:  |  Size: 33 KiB

View File

@ -70,36 +70,67 @@ $productId = isset($_GET['id']) ? (int)$_GET['id'] : 0;
$result = $stmt->get_result();
$product = $result->fetch_assoc();
$alreadyInWishlist = false;
if (isset($_SESSION['user_id'])) {
$stmtCheck = mysqli_prepare(
$conn,
"SELECT 1 FROM userFavorites
WHERE userID = ? AND productID = ?
LIMIT 1"
);
if ($stmtCheck) {
mysqli_stmt_bind_param(
$stmtCheck,
"ii",
$_SESSION['user_id'],
$productId
);
mysqli_stmt_execute($stmtCheck);
mysqli_stmt_store_result($stmtCheck);
if (mysqli_stmt_num_rows($stmtCheck) > 0) {
$alreadyInWishlist = true;
}
mysqli_stmt_close($stmtCheck);
}
}
?>
<?php
$alreadyInWishlist = null;
if (
$_SERVER['REQUEST_METHOD'] === 'POST' &&
isset($_POST['add_wishlist']) &&
isset($_SESSION['user_id'])
) {
$userId = (int)$_SESSION['user_id'];
$productIdPost = (int)$_POST['product_id'];
if ($productIdPost > 0 && $alreadyInWishlist == null) {
if (!$alreadyInWishlist) {
$stmtFav = mysqli_prepare(
$conn,
"INSERT IGNORE INTO userFavorites (productID, userID) VALUES (?, ?)"
"INSERT INTO userFavorites (productID, userID) VALUES (?, ?)"
);
if ($stmtFav) {
mysqli_stmt_bind_param($stmtFav, 'ii', $productIdPost, $userId);
mysqli_stmt_bind_param(
$stmtFav,
'ii',
$productId,
$_SESSION['user_id']
);
mysqli_stmt_execute($stmtFav);
mysqli_stmt_close($stmtFav);
$alreadyInWishlist = true;
}
}
}
?>
<div class="product-wrapper">
@ -222,7 +253,7 @@ $productId = isset($_GET['id']) ? (int)$_GET['id'] : 0;
<div class="shop-middle">
<div class="shop-shipping">
Versand: <?= htmlspecialchars($shop['shippingCost']) ?>
Versand: <?= htmlspecialchars($shop['shippingCost']) ?> &nbsp &nbsp &nbsp
Lieferzeit: <?= htmlspecialchars($shop['shippingTime']) ?> Werktage
</div>
<div class="shop-stock <?= $shop['inStock'] ? 'in-stock' : 'out-stock' ?>">

View File

@ -24,35 +24,21 @@ if (!$conn)
}
?>
<?php
$activeCategory = isset($_GET['category']) ? $_GET['category'] : 'all';
?>
<?php
$categories = [
'iphone' => ['id' => 20, 'label' => 'iPhone'],
'ipad' => ['id' => 21, 'label' => 'iPad'],
'macbook' => ['id' => 22, 'label' => 'MacBook'],
'airpods' => ['id' => 23, 'label' => 'AirPods'],
'accessories' => ['id' => 24, 'label' => 'Accessories'],
];
?>
<?php foreach ($categories as $key => $cat): ?>
<?php if ($activeCategory === 'all' || $activeCategory === $key): ?>
<?php
if (!isset($_SESSION['user_id'])) {
header("Location: login.php");
exit();
}
?>
<?php
$stmt = $conn->prepare("
SELECT productID, model, description, imagePath
FROM products
WHERE categoryID = ?
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", $cat['id']); // i = integer
$stmt->bind_param("i", $_SESSION['user_id']);
$stmt->execute();
$result = $stmt->get_result();
@ -60,7 +46,6 @@ $categories = [
<?php if ($result->num_rows > 0): ?>
<section class="product-section">
<h2><?= htmlspecialchars($cat['label']) ?></h2>
<div class="product-scroll">
<?php while ($product = $result->fetch_assoc()): ?>
@ -82,10 +67,6 @@ $categories = [
<?php $stmt->close(); ?>
<?php endif; ?>
<?php endforeach; ?>
<head>
<meta charset="UTF-8">