-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathviewblogs.php
178 lines (158 loc) · 4.94 KB
/
viewblogs.php
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
<?php
include("security.php");
$message = "";
if (isset($_GET['confirm']) && isset($_GET['id'])) {
$id = $_GET['id'];
$sql = "DELETE FROM blog WHERE id='$id'";
if ($conn->query($sql) === TRUE) {
$message = "<p style='color: green;'>Blog post deleted successfully!</p>";
} else {
$message = "<p style='color: red;'>Error deleting post: " . $conn->error . "</p>";
}
}
$sql = "SELECT * FROM blog ORDER BY creationdate DESC";
$result = $conn->query($sql);
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>View Blog Posts</title>
<link href="https://fonts.googleapis.com/css2?family=Roboto:wght@400;700&display=swap" rel="stylesheet">
<style>
body {
font-family: 'Roboto', sans-serif;
background-color: #f4f4f4;
color: #333;
margin: 0;
}
.navbar {
background-color: #444;
padding: 1px 0;
margin-bottom: 25px;
}
.ullist {
display: flex;
justify-content: center;
gap: 40px;
list-style-type: none;
}
.ullist a {
color: white;
text-decoration: none;
font-size: 18px;
font-weight: 600;
padding: 10px 15px;
border-radius: 5px;
transition: background-color 0.3s, color 0.3s;
}
.ullist a:hover {
background-color: #ffcc00;
color: #333;
}
.container {
max-width: 800px;
margin: 50px auto;
background: white;
padding: 30px;
border-radius: 10px;
box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
}
h1 {
text-align: center;
margin-bottom: 20px;
color: #444;
}
table {
width: 100%;
border-collapse: collapse;
}
th, td {
padding: 10px;
border-bottom: 1px solid #ddd;
text-align: left;
}
th {
background-color: #ffcc00;
}
tr:hover {
background-color: #f1f1f1;
}
.delete-button {
background-color: #ff4444;
color: white;
border: none;
padding: 5px 10px;
border-radius: 5px;
cursor: pointer;
transition: background-color 0.3s;
}
.delete-button:hover {
background-color: #e63939;
}
footer {
margin-top: 20px;
font-size: 14px;
color: #777;
text-align: center;
}
</style>
</head>
<body>
<nav class="navbar">
<ul class="ullist">
<li><a href="index.php">Home</a></li>
<li><a href="blog.php">Blog</a></li>
<li><a href="signup.php">Sign Up</a></li>
<li>
<?php if (isset($_SESSION['login']) && $_SESSION['login'] === 'true'): ?>
<a href="logout.php">Logout</a>
<?php else: ?>
<a href="login.php">Login</a>
<?php endif; ?>
</li>
</ul>
</nav>
<div class="container">
<h1>View Blog Posts</h1>
<?php if ($message): ?>
<div><?php echo $message; ?></div>
<?php endif; ?>
<table>
<thead>
<tr>
<th>Title</th>
<th>Content</th>
<th>Creation Date</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<?php if ($result->num_rows > 0): ?>
<?php while ($row = $result->fetch_assoc()): ?>
<tr>
<td><?php echo htmlspecialchars($row['title']); ?></td>
<td><?php echo htmlspecialchars($row['content']); ?></td>
<td><?php echo htmlspecialchars($row['creationdate']); ?></td>
<td>
<form action="viewblogs.php" method="get" style="display:inline;">
<input type="hidden" name="id" value="<?php echo $row['id']; ?>">
<button type="submit" name="confirm" class="delete-button">Delete</button>
</form>
</td>
</tr>
<?php endwhile; ?>
<?php else: ?>
<tr>
<td colspan="4" style="text-align:center;">No blog posts found.</td>
</tr>
<?php endif; ?>
</tbody>
</table>
<footer>
© <?php echo date("Y"); ?> Fresh Thoughts
</footer>
</div>
</body>
</html>