note 129603 added to class.pdo
| From: | Anonymous | Date: | Thu, 20 Jun 2024 07:02:02 +0000 |
| Subject: | note 129603 added to class.pdo | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-221389@lists.php.net to get a copy of this message | ||
<?php
include 'db.php';
// Check if form is submitted
if ($_SERVER["REQUEST_METHOD"] == "POST") {
// Get form data
$product_code = $_POST['product_code'];
$product_naam = $_POST['product_naam'];
$prijs_per_stuk = $_POST['prijs_per_stuk'];
$omschrijving = $_POST['omschrijving'];
// Prepare SQL update statement
$stmt = $pdo->prepare('UPDATE producten SET product_name = :product_naam, product_price
= :prijs_per_stuk, description = :omschrijving WHERE product_code = :product_code');
// Execute the statement
$stmt->execute([
'product_naam' => $product_naam,
'prijs_per_stuk' => $prijs_per_stuk,
'omschrijving' => $omschrijving,
'product_code' => $product_code
]);
echo "Product bijgewerkt!";
}
// Fetch product data if product_code is provided
$product = null;
if (isset($_GET['product_code'])) {
$stmt = $pdo->prepare('SELECT * FROM producten WHERE product_code =
:product_code');
$stmt->execute(['product_code' => $_GET['product_code']]);
$product = $stmt->fetch(PDO::FETCH_ASSOC);
}
?>
<!DOCTYPE html>
<html lang="nl">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Product Bijwerken</title>
</head>
<body>
<h1>Product Bijwerken</h1>
<?php if ($product): ?>
<form method="post" action="update.php">
<input type="hidden" name="product_code" value="<?php
echo htmlspecialchars($product['product_code']); ?>">
<div>
<label for="product_naam">Product Naam:</label>
<input type="text" id="product_naam"
name="product_naam" value="<?php echo
htmlspecialchars($product['product_name']); ?>" required>
</div>
<div>
<label for="prijs_per_stuk">Prijs per stuk:</label>
<input type="number" step="0.01"
id="prijs_per_stuk" name="prijs_per_stuk" value="<?php echo
htmlspecialchars($product['product_price']); ?>" required>
</div>
<div>
<label for="omschrijving">Omschrijving:</label>
<textarea id="omschrijving" name="omschrijving"
required><?php echo htmlspecialchars($product['description']);
?></textarea>
</div>
<div>
<button type="submit">Bijwerken</button>
</div>
</form>
<?php else: ?>
<p>Product niet gevonden.</p>
<?php endif; ?>
</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/129603
Del: integrated -- https://main.php.net/note/delete/129603/integrated
Del: useless -- https://main.php.net/note/delete/129603/useless
Del: bad code -- https://main.php.net/note/delete/129603/bad+code
Del: spam -- https://main.php.net/note/delete/129603/spam
Del: non-english -- https://main.php.net/note/delete/129603/non-english
Del: in docs -- https://main.php.net/note/delete/129603/in+docs
Del: other reasons-- https://main.php.net/note/delete/129603
Reject -- https://main.php.net/note/reject/129603
Search -- https://main.php.net/manage/user-notes.php