-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathedit.php
More file actions
49 lines (37 loc) · 1.28 KB
/
edit.php
File metadata and controls
49 lines (37 loc) · 1.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<?php include 'db.php'; ?>
<?php
$id = $_GET['id'];
$post = $conn->query("SELECT * FROM posts WHERE id=$id")->fetch_assoc();
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$title = $_POST['title'];
$content = $_POST['content'];
$conn->query("UPDATE posts SET title='$title', content='$content' WHERE id=$id");
header("Location: index.php");
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Edit Post</title>
<script src="https://cdn.tailwindcss.com"></script>
</head>
<body class="bg-gray-100">
<div class="bg-purple-800 text-white p-4 text-xl font-semibold">
Edit Post
</div>
<div class="flex justify-center mt-10">
<form method="POST" class="bg-white p-6 rounded-xl shadow w-full max-w-3xl">
<h2 class="text-xl font-bold mb-4">Edit Post</h2>
<input type="text" name="title"
value="<?php echo $post['title']; ?>"
class="w-full border p-2 rounded mb-3 focus:ring-2 focus:ring-indigo-400">
<textarea name="content"
class="w-full border p-2 rounded mb-3 focus:ring-2 focus:ring-indigo-400"><?php echo $post['content']; ?></textarea>
<button type="submit"
class="w-full bg-purple-800 text-white py-2 rounded-lg hover:bg-indigo-700">
Update
</button>
</form>
</div>
</body>
</html>