Programmieren & Softwareentwicklung

Wenn Du nicht nur Anwender sein willst, sondern auch aktiv programmierst oder mit dem Gedanken spielst, dann warten hier die passenden Fragen und Antworten auf Dich.

26.813 Beiträge

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")
?>


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>

Python discord NonType Error?

Ich habe einen Error in meinem Code:

async def on_submit(self, interaction2: discord.Interaction):
    response = await sendRequests(str(self.username), str(self.email), str(self.password))
    if response == "email":
        await interaction2.response.send_message("Incorrect email format", ephemeral=True)
        return
    if response == "password":
        await interaction2.response.send_message("Incorrect password format. The password must meet these requirements: \nOne Uppercase letter \nOne lowercase letter \nOne number\n A special character ", ephemeral=True)
        return
    if response == "maintenance":
        await interaction2.response.send_message("The system is currently under maintenance. Please look in #news for more infos.", ephemeral=True)
    query = "INSERT INTO users VALUES (?, ?, ?, ?)"
    main.cursor.execute(query, (interaction2.user.id, str(self.username), str(self.email), str(self.password)))
    main.database.commit()
    await interaction2.response.send_message("You are now in the registration process. This can take up to one hour.", ephemeral=True)
    channel = main.bot.get_channel(1309925591146958933)
    await channel.send("make a recaptcha, registration from user : " + str(interaction2.user.name) + " with id: " + str(interaction2.user.id))

Error:
[2024-11-23 19:32:43] [ERROR  ] discord.ui.modal: Ignoring exception in modal <RegisterModal timeout=None children=3>:

Traceback (most recent call last):

 File ".venv\Lib\site-packages\discord\ui\modal.py", line 189, in _scheduled_task

   await self.on_submit(interaction)

 File "TestButton.py", line 41, in on_submit

   await channel.send("make a recaptcha, registration from user : " + str(interaction2.user.name) + " with id: " + str(interaction2.user.id))

         ^^^^^^^^^^^^

AttributeError: 'NoneType' object has no attribute 'send'

Ask Me Anything: Themenspecials