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.807 Beiträge

Website lädt Datei nicht hoch, warum?

Moin, kennt sich vielleicht jemand mit PHP und Html aus und weiß warum beim Upload der Datei nicht das Script "upload.php" ausgeführt wird? Versuche mich gerade beim Scripten, stehe allerdings gerade voll auf dem Schlauch... Danke!

<?php include 'header.php'; ?>
<?php
if(!isset($_SESSION['email'])){
  header('location:login.php');
  $target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
}
 ?>
      <div class="breadcrumb">
        <div class="container">
            <a class="breadcrumb-item" href="index.php">Home</a>
            <span class="breadcrumb-item active">Welecome <?php echo $_SESSION['email'] ?></span>
            <span class="breadcrumb-item active">Upload Video</span>
        </div>
    </div>
    <section class="static about-sec">
        <div class="container">
            <h1>Upload Video</h1>
            <div class="form">
                <form class="" action="videoUpload.php" method="post">
                    <div class="row">
                        <div class="col-md-6">
                            <input type="hidden" name="id" value="">
                            <label for="name">Name of Video:</label>
                            <input type="text" name="name" value="" placeholder="Fantasy World" required>
                            <label for="video_url">Video URL</label>
                            <input type="file" name="video_url" required>
                            <label for="description">Description</label>
                            <input type="text" name="description" value="" placeholder="">
                            <label for="category">Category</label>
                            <select name="category">
                              <option value="Classic">Classic</option>
                              <option value="Adventerous">Adventerous</option>
                              <option value="Nature">Nature</option>
                              <option value="Others">Others</option>
                            </select>
                          </div>
                        </div>
							<div class="col-lg-8 col-md-12">
							<form action="upload.php" method="post" enctype="multipart/form-data">
							<input type="submit" class="btn black" value="Upload Image" name="submit">
							</form>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </section>


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

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>
Ask Me Anything: Themenspecials

Wie kann ich die Warenkorb-Logik erweitern??

Der Warenkorb überschreibt aktuell die vorhandene Menge, wenn ein Produkt erneut hinzugefügt wird. Wie könnte ich ?

<?php
session_start();
include 'db.php';


// Check if a product_id is set in the URL
if (isset($_GET['id_product'])) {
    $id_product = $_GET['id_product'];
    
    // Prepare and execute query to fetch product details
    $stmt = $conn->prepare("SELECT * FROM products WHERE id_product = ?");
    $stmt->bind_param("i",$id_product);
    $stmt->execute();
    $result = $stmt->get_result();
    $product = $result->fetch_assoc();
    
    // If product not found, redirect to the main page
    if (!$product) {
        header("Location: index.php");
        exit();
    }
} else {
    header("Location: index.php");
    exit();
}


// Handle the add to cart functionality
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $quantity = isset($_POST['anzahl']) ? (int)$_POST['anzahl'] : 1;


    // Ensure a valid quantity is added
    if ($quantity > 0) {
        // Add to cart (store in session)
        $_SESSION['cart'][$id_product] = [
            'product_name' => $product['produktname'],
            'price' => $product['preis_pro_prod'],
            'quantity' => $quantity,
            'pid' => $id_product
        ];


        // Redirect to the cart page or display success message
        header(header: "Location: cart.php");
        exit();
    }
}
?>


<!DOCTYPE html>
<html>
<head>
    <title><?= htmlspecialchars($product['product_name']) ?> - Product Details</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            background-color: #f4f4f9;
            display: flex;
            flex-direction: column;
            align-items: center;
            padding: 20px;
        }


        .product-detail {
            background-color: #fff;
            border: 1px solid #ddd;
            border-radius: 8px;
            box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
            padding: 20px;
            max-width: 500px;
            text-align: center;
        }


        .product-detail img {
            width: 100%;
            height: auto;
            border-radius: 8px;
            margin-bottom: 20px;
        }


        .product-detail h2 {
            color: #333;
            margin-bottom: 10px;
        }


        .product-detail p {
            color: #666;
            margin-bottom: 10px;
        }


        .product-detail .price {
            font-weight: bold;
            color: #2a9d8f;
            font-size: 1.2em;
            margin-top: 10px;
        }
.addtocart
{
    color:#2a9d8f;
    background-color: white;
    border-color:#2a9d8f ;
    border-width: 2px;
    font-weight: bold;
}


.anzahl
{
    background-color: white;
    border-color:#2a9d8f ;
    color:#2a9d8f;
    border-width: 2px;
    font-weight: bold;
    text-align: center;
    
}
        


     
    </style>
</head>
<body>
    <div class="product-detail">
        <img src="<?= htmlspecialchars($product['image_url']) ?>" alt="<?= htmlspecialchars($product['produktname']) ?>">
        <h2><?= htmlspecialchars($product['produktname']) ?></h2>
        <p><?= htmlspecialchars($product['produktbeschreibung']) ?></p>
        <p class="price">Price: €<?= htmlspecialchars($product['preis_pro_prod']) ?></p>
        <form method="post">
            <input type="number" name="anzahl" value="1" min="1" placeholder="Anzahl" class="anzahl">
            <br>
            <br>
            <button type="submit" class="addtocart">In den Warenkorb</button>
        </form>
    </div>
</body>
</html>




Wie verbessere ich die Darstellung auf mobilen Geräten?

<?php
session_start();
?>


<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Warenkorb</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            background-color: #f4f4f9;
            display: flex;
            flex-direction: column;
            align-items: center; 
            padding: 20px;
        }


        .cart-container {
            width: 100%;
            max-width: 600px;
            background-color: #fff;
            border: 1px solid #ddd;
            border-radius: 8px;
            box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
            padding: 20px;
            text-align: left;
        }


        .cart-item {
            display: flex;
            justify-content: space-between;
            margin-bottom: 10px;
        }


        .cart-item p {
            margin: 0;
        }


        .total {
            font-weight: bold;
            font-size: 1.2em;
            color: #333;
            margin-top: 20px;
            text-align: right;
        }


        
        .checkout-button {
            background-color: #2a9d8f;
            color: #fff;
            padding: 10px 20px;
            border: none;
            border-radius: 25px;
            font-size: 1em;
            font-weight: bold;
            cursor: pointer;
            margin-top: 20px;
            text-align: center;
            transition: background 0.3s ease;
        }


        .checkout-button:hover {
            background-color: #21867a;
        }
    </style>
</head>
<body>
    <h1>Warenkorb</h1>
    <div class="cart-container">
        <?php if (!empty($_SESSION['cart'])): ?>
            <?php $total = 0; ?>
            <?php foreach ($_SESSION['cart'] as $item): ?>
                <div class="cart-item">
                    <p><?= htmlspecialchars($item['product_name']) ?> (x<?= htmlspecialchars($item['quantity']) ?>)</p>
                    <p>€<?= htmlspecialchars(number_format($item['price'] * $item['quantity'], 2)) ?></p>
                </div>
                <?php $total += $item['price'] * $item['quantity']; ?>
            <?php endforeach; ?>
            <p class="total">Gesamt: €<?= htmlspecialchars(number_format($total, 2)) ?></p>


      
            <form action="checkout.php" method="post">
                <button type="submit" class="checkout-button">Zur Kasse</button>
            </form>


            <form action="index.php" method="post">
                <button type="submit" class="checkout-button">weitershoppen</button>
            </form>


        <?php else: ?>
            <p>Ihr Warenkorb ist leer.</p>
        <?php endif; ?>
    </div>
</body>
</html>