Το Adobe Dreamweaver (legacy) παρείχε visual tools για δημιουργία PHP forms. Σημαντικό: Το Dreamweaver έχει αποκατασταθεί (EOL 2021) και τα server behaviors είναι deprecated. Σύγχρονα projects χρησιμοποιούν frameworks (Laravel, Symfony) ή τουλάχιστον PDO/prepared statements.
<!-- 1. Αλλαγή τίτλου -->
<title>Update Post</title>
<!-- 2. Προσθήκη hidden πεδίου για ID -->
<input type="hidden" name="id" value="<?php echo $row_rsRecord['id']; ?>">
<!-- 3. Προ-γεμίσμα πεδίων με υπάρχοντα δεδομένα -->
<input type="text" name="title" value="<?php echo htmlspecialchars($row_rsRecord['title']); ?>">
<textarea name="content"><?php echo htmlspecialchars($row_rsRecord['content']); ?></textarea>
<!-- 4. Αλλαγή κουμπιού submit -->
<input type="submit" name="update" value="Update Post">
<?php
// config.php
$host = 'localhost';
$db = 'my_database';
$user = 'db_user';
$pass = 'db_pass';
$charset = 'utf8mb4';
$dsn = "mysql:host=$host;dbname=$db;charset=$charset";
$options = [
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
PDO::ATTR_EMULATE_PREPARES => false,
];
try {
$pdo = new PDO($dsn, $user, $pass, $options);
} catch (\PDOException $e) {
throw new \PDOException($e->getMessage(), (int)$e->getCode());
}
?>
<?php
require 'config.php';
$id = $_GET['id'] ?? null;
if (!$id) { die('Invalid ID'); }
// Fetch existing data
$stmt = $pdo->prepare('SELECT * FROM posts WHERE id = ?');
$stmt->execute([$id]);
$post = $stmt->fetch();
if (!$post) { die('Post not found'); }
// Handle form submission
$errors = [];
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$title = trim($_POST['title'] ?? '');
$content = trim($_POST['content'] ?? '');
if (empty($title)) { $errors[] = 'Title is required'; }
if (empty($content)) { $errors[] = 'Content is required'; }
if (empty($errors)) {
$stmt = $pdo->prepare('UPDATE posts SET title = ?, content = ?, updated_at = NOW() WHERE id = ?');
$stmt->execute([$title, $content, $id]);
header('Location: view.php?id=' . $id);
exit;
}
}
?>
<!DOCTYPE html>
<html lang="el">
<head>
<meta charset="UTF-8">
<title>Update Post</title>
<style>
.error { color: red; margin-bottom: 1rem; }
label { display: block; margin-top: 1rem; }
input, textarea { width: 100%; padding: 0.5rem; margin-top: 0.25rem; }
button { margin-top: 1rem; padding: 0.75rem 1.5rem; }
</style>
</head>
<body>
<h1>Update Post</h1>
<?php if ($errors): ?>
<div class="error">
<ul><?php foreach ($errors as $e): ?><li><?= htmlspecialchars($e) ?></li><?php endforeach; ?></ul>
</div>
<?php endif; ?>
<form method="POST">
<input type="hidden" name="id" value="<?= $post['id'] ?>">
<label>
Title:
<input type="text" name="title" value="<?= htmlspecialchars($post['title']) ?>" required>
</label>
<label>
Content:
<textarea name="content" rows="10" required><?= htmlspecialchars($post['content']) ?></textarea>
</label>
<button type="submit">Update Post</button>
</form>
</body>
</html>
| Χαρακτηριστικό | Dreamweaver Server Behaviors | Modern PDO |
|---|---|---|
| Security | Vulnerable (συχνά raw queries) | Prepared statements, SQL injection proof |
| Maintainability | Κρυμμένος κώδικας, δύσκολο debug | Καθαρός, ορατός, testable κώδικας |
| Flexibility | Περιορισμένο στα UI options | Πλήρης έλεγχος |
| Dependencies | Dreamweaver-specific | Μόνο PHP core (PDO) |
| Future-proof | Deprecated/Removed | Standard, actively maintained |
Πνευματικά δικαιώματα © Γνώση Υπολογιστών Όλα τα δικαιώματα διατηρούνται.