Wie implementiere ich eine Mehrfachauswahl?

Kann ich es ermöglichen, dass der Benutzer mehrere Marken oder Baujahre gleichzeitig auswählen kann? Wie würde ich den Query entsprechend anpassen?


<?php
    require "includes/conn.inc.php";
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Modelle</title>
</head>
<body>
    <h1>Modelle</h1>
    <form method="post">
        <label for="marke">
            Marke
            <input name="marke" type="text">
        </label>
        <label for="modell">
            Modell
            <input name="modell" type="text">
        </label>
        <label for="baujahr">
            Baujahr
            <input name="baujahr" type="text">
        </label>
        <button type="submit">Suchen</button>
    </form>
    <ul>
        <?php
            // Loop through tbl_marken and create WHERE clause
            $where_marke = "";
            if (count($_POST) > 0) {
                if (array_key_exists("marke", $_POST)) {
                    if (strlen($_POST["marke"] > 0)) {
                        $where_marke = "WHERE Markenname LIKE '%" . $_POST["marke"] . "%'";
                    }
                }
            }
            $conn = openConn();
            $markenSql = "
                SELECT 
                    * 
                FROM tbl_marken "
                . $where_marke . "
                ORDER BY Markenname ASC
            ";
            $marken = $conn->query($markenSql) or die($conn->error);
            while ($marke = $marken->fetch_object()) {
                echo "<li>";
                    echo $marke->Markenname;
                echo "</li>";
                
                // Loop through tbl_modell and create WHERE clause
                echo "<ul>";
                    $where_modell = "";
                    if (array_key_exists("modell", $_POST)) {
                        if (strlen($_POST["modell"] > 0)) {
                            $where_modell = " AND Modell LIKE '%" . $_POST["modell"] . "%'";
                        }
                    }
                    $modellSql = "
                        SELECT 
                            * 
                        FROM tbl_modelle 
                        WHERE FIDMarke=" . $marke->IDMarke . $where_modell . "
                        ORDER BY tbl_modelle.Modell ASC
                    ";
                    $modelle = $conn->query($modellSql) or die($conn->error);
                    while ($modell = $modelle->fetch_object()) {
                        echo "<li>";
                            echo $modell->Modell;
                        echo "</li>";   


                        // Loop through baureihen and create WHERE clause
                        echo "<ul>";
                            $where_bau = ["FIDModell=" . $modell->IDModell];
                            if (array_key_exists("baujahr", $_POST)) {
                                if(intval($_POST["baujahr"])>0) {
                                    $where_bau[] = "BaujahrVon<=" . $_POST["baujahr"];
                                    $where_bau[] = "BaujahrBis>=" . $_POST["baujahr"];
                                }
                            }
                            $bauSql = "
                                SELECT 
                                    * 
                                FROM tbl_baureihen 
                                WHERE " . implode(" AND ", $where_bau)
                            ;
                            $baureihen = $conn->query($bauSql) or die($conn->error);
                            while ($baureihe = $baureihen->fetch_object()) {                               
                                echo "<li><a href='modell_teile.php?IDBaureihe=" . $baureihe->IDBaureihe . "'>" . $baureihe->BaujahrVon . " - " . $baureihe->BaujahrBis . " </a></li>";
                            }
                        echo "</ul>";
                    }
                echo "</ul>";
            }
        ?>
    </ul>
</body>
</html>
Datenbank, Programmiersprache

Problem mit falscher Darstellung des Euro-Zeichens (€) in FPDF (erscheint als "â")?

Die restlichen Inhalte werden korrekt dargestellt, aber das Euro-Zeichen scheint nicht richtig kodiert zu werden. Meine Vermutung ist, dass es an der Zeichenkodierung (UTF-8 oder ISO-8859-1) oder an der verwendeten Schriftart liegt.

Hat jemand eine Idee, wie ich dieses Problem beheben kann?

Vielen Dank im Voraus für eure Hilfe!


<?php


session_start();
include "db.php";


// Holen der Bestelldaten
$query = "SELECT 
            u.vorname, 
            u.nachname, 
            b.bestelldatum, 
            b.bestelladresse, 
            bp.anzahl, 
            bp.preis, 
            p.produktname 
          FROM 
            user u
          JOIN 
            bestellungen b ON u.id_user = b.id_user
          JOIN 
            bestellungen_products bp ON b.id_bestellung = bp.id_bestellung
          JOIN 
            products p ON bp.id_product = p.id_product 
          WHERE 
            b.id_bestellung = ?";


$id_order = $_GET["order_id"];
$stmt = $conn->prepare($query);
$stmt->bind_param("i", $id_order);
$stmt->execute();
$result = $stmt->get_result();


$order = $result->fetch_assoc();
$rechnungs_nummer = $id_order;
$rechnungs_datum = $order["bestelldatum"];
$lieferdatum = date("Y-m-d", strtotime($rechnungs_datum . " +2 weeks"));


// Neues PDF erstellen
require_once('fpdf/fpdf.php');
$pdf = new FPDF();
$pdf->AddPage();


// Titel und Rechnungsinformationen
$pdf->SetFont('Helvetica', 'B', 16);
$pdf->Cell(190, 10, 'Rechnung', 0, 1, 'C');
$pdf->SetFont('Helvetica', '', 12);
$pdf->Cell(100, 10, 'Rechnungsnummer: ' . $rechnungs_nummer);
$pdf->Cell(90, 10, 'Rechnungsdatum: ' . $rechnungs_datum, 0, 1);
$pdf->Cell(100, 10, 'Lieferdatum: ' . $lieferdatum, 0, 1);


// Empfängerinformationen
$pdf->Ln(10);
$pdf->Cell(100, 10, 'Kunde:');
$pdf->Ln(5);
$pdf->Cell(100, 10, $order["vorname"] . " " . $order["nachname"]);
$pdf->Ln(5);
$pdf->Cell(100, 10, $order["bestelladresse"]);


// Postenübersicht
$pdf->Ln(15);
$pdf->SetFont('Helvetica', 'B', 12);
$pdf->Cell(90, 10, 'Produkt', 1);
$pdf->Cell(30, 10, 'Menge', 1);
$pdf->Cell(30, 10, 'Preis', 1);
$pdf->Cell(40, 10, 'Gesamt', 1, 1);
$pdf->SetFont('Helvetica', '', 12);


$gesamtpreis = 0;
do {
    $produktname = $order["produktname"];
    $anzahl = $order["anzahl"];
    $preis = $order["preis"];
    $gesamt = $anzahl * $preis;
    $gesamtpreis += $gesamt;


    $pdf->Cell(90, 10, $produktname, 1);
    $pdf->Cell(30, 10, $anzahl, 1, 0, 'C');
    $pdf->Cell(30, 10, number_format($preis, 2, ',', '') . ' €', 1, 0, 'R');
    $pdf->Cell(40, 10, number_format($gesamt, 2, ',', '') . ' €', 1, 1, 'R');
} while ($order = $result->fetch_assoc());


// Gesamtsumme
$pdf->SetFont('Helvetica', 'B', 12);
$pdf->Ln(5);
$pdf->Cell(150, 10, 'Gesamtsumme:', 0, 0, 'R');
$pdf->Cell(40, 10, number_format($gesamtpreis, 2, ',', '') . ' €', 0, 1, 'R');


// Ausgabe des PDFs
$pdf->Output('F', 'Rechnung_' . $rechnungs_nummer . '.pdf');


//header("location:mail.php?order_id=$id_order")
header("location:confirmation.php?order_id=$id_order")
?>


Webseite, PHP

Warum wirft htmlspecialchars einen Syntaxfehler in meinem PHP-Webshop-Code?

<?php
include 'db.php';

$query = "SELECT * FROM products";
$result = $conn->query($query);
?>

<!DOCTYPE html>
<html>
<head>
    <title>Webshop</title>
    <style>
        /* Basic styling for the body */
        body {
            font-family: Arial, sans-serif;
            background-color: #f4f4f9;
            margin: 0;
            padding: 20px;
            display: flex;
            flex-direction: column;
            align-items: center;
        }

        /* Styling for the main heading */
        h1 {
            color: #333;
            margin-bottom: 20px;
        }

        /* Container for all products */
        .products-container {
            display: flex;
            flex-wrap: wrap;
            gap: 20px;
            justify-content: center;
        }

        /* Individual product card */
        .product-card {
            background-color: #fff;
            border: 1px solid #ddd;
            border-radius: 8px;
            box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
            overflow: hidden;
            width: 200px;
            text-align: center;
            padding: 15px;
            transition: transform 0.2s;
        }

        .product-card:hover {
            transform: scale(1.05);
        }

        /* Styling for the product image */
        .product-card img {
            width: 100%;
            height: auto;
            border-radius: 8px;
            transition: opacity 0.2s;
        }

        .product-card img:hover {
            opacity: 0.8;
        }

        /* Styling for product name */
        .product-card h2 {
            font-size: 1.2em;
            color: #333;
            margin: 10px 0;
        }

        /* Styling for product description and price */
        .product-card p {
            color: #666;
            font-size: 0.9em;
            margin: 5px 0;
        }

        .product-card .price {
            font-weight: bold;
            color: #2a9d8f;
        }

        /* Link styling */
        a {
            text-decoration: none;
            color: inherit;
        }
    </style>
</head>
<body>
    <h1>Products</h1>
    <div class="products-container">
        <?php while ($product = $result->fetch_assoc()): ?>
            <div class="product-card">
                <a href="product.php?id_product=<?= htmlspecialchars( $product['id_product']) ?>">
                    <h2><?= htmlspecialchars( $product['produktname']) ?></h2>
                    <!-- Make the image clickable to open the product details page -->
                    <img src="<?= htmlspecialchars($product['image_url']) ?>" alt="<?= htmlspecialchars($product['produktname']) ?>">
              
                <p><?= htmlspecialchars($product['produktbeschreibung']) ?></p>
                <p class="price">Price: €<?= htmlspecialchars($product['preis_pro_prod']) ?></p>
                  </a>
            </div>
        <?php endwhile; ?>
    </div>
</body>
</html>
HTML, CSS