note 129601 added to class.pdo

From: Date: Thu, 20 Jun 2024 07:00:40 +0000
Subject: note 129601 added to class.pdo
Groups: php.notes 
Request: Send a blank email to php-notes+get-221388@lists.php.net to get a copy of this message
<?php // Include the database connection include 'db.php'; $host = "loaclhost"; $db ="winkel"; $user = "root"; $pass =""; // Check if the form is submitted if ($_SERVER["REQUEST_METHOD"] == "POST") { // Get the form data $product_naam = $_POST['product_naam']; $prijs_per_stuk = $_POST['prijs_per_stuk']; $omschrijving = $_POST['omschrijving']; // Prepare and execute the insert statement try { $pdo =new PDO("mysql:host=$host;dbname=$db;",$user,$pass); $stmt = $pdo->prepare("INSERT INTO product (product_naam, prijs_per_stuk, omschrijving) VALUES (:product_naam, :prijs_per_stuk, :omschrijving)"); $stmt->execute([ 'product_naam' => $product_naam, 'prijs_per_stuk' => $prijs_per_stuk, 'omschrijving' => $omschrijving ]); echo "Nieuw product succesvol toegevoegd"; } catch (PDOException $error) { echo "Error: " . $error->getMessage(); } } $stmt = $pdo->query("SELECT * FROM product"); //fetch = haalt 1data op. //fetchall = haalt alles op. $result = $stmt->fetchAll(); ?> <!DOCTYPE html> <html lang="nl"> <head> <meta charset="UTF-8"> <title>product Toevoegen</title> </head> <body> <h2>product Toevoegen</h2> <form method="post" action="insert.php"> <label for="product_naam">product Name:</label> <input type="text" id="product_naam" name="product_naam" required><br><br> <label for="prijs_per_stuk">prijs per Stuk:</label> <input type="text" id="prijs_per_stuk" name="prijs_per_stuk" required><br><br> <label for="omschrijving">Omschrijving:</label> <textarea id="omschrijving" name="omschrijving" required></textarea><br><br> <input type="submit" value="Toevoegen"> </form> <table> <tr> <th>Product ID</th> <th>Name</th> <th>Price</th> <th colspan="2">Action</th> </tr> <tr> <?php foreach ($result as $product) { echo "<td>". $product['productId'] . "</td>"; echo "<td>". $product['name'] . "</td>"; echo "<td>". $product['prijs'] . "</td>"; echo "<td><a href='edit-product.php?productId='". $product['productId'] . "'>Edit</a></td>"; echo "<td><a href='delete-product.php?productId='". $product['productId'] . "'>Delete</a></td>"; ?> </tr> <?php } ?> </table> </body> </html> ---- Server IP: 45.112.84.4 Probable Submitter: 80.90.5.137 (proxied: 145.100.74.49) ---- Manual Page -- https://php.net/manual/en/class.pdo.php Edit -- https://main.php.net/note/edit/129601 Del: integrated -- https://main.php.net/note/delete/129601/integrated Del: useless -- https://main.php.net/note/delete/129601/useless Del: bad code -- https://main.php.net/note/delete/129601/bad+code Del: spam -- https://main.php.net/note/delete/129601/spam Del: non-english -- https://main.php.net/note/delete/129601/non-english Del: in docs -- https://main.php.net/note/delete/129601/in+docs Del: other reasons-- https://main.php.net/note/delete/129601 Reject -- https://main.php.net/note/reject/129601 Search -- https://main.php.net/manage/user-notes.php

« previous php.notes (#221388) next »