-
Notifications
You must be signed in to change notification settings - Fork 1
/
ad_blog.php
202 lines (182 loc) · 8.07 KB
/
ad_blog.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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
<?php
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
if (isset($_POST['submit'])) {
$title = $_POST['blog_title'];
$author = $_POST['blog_author'];
$date = $_POST['blog_date'];
$content = $_POST['blog_content'];
$name = $_POST['blog_name'];
$conn = new mysqli("sql100.infinityfree.com", "if0_34678114", "943Uw88q1QdrSMC","if0_34678114_serenebeauty") or die("Connect failed: %s\n" . $conn->error);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
// Prepare and execute the SQL query to insert other data into the database
$stmt = $conn->prepare("INSERT INTO blogs (title, author, date, content, bl_name) VALUES (?, ?, ?, ?, ?)");
$stmt->bind_param("sssss", $title, $author, $date, $content, $name);
$stmt->execute();
$blogId = $stmt->insert_id; // Retrieve the ID of the inserted blog
// Process and insert the image data into the database
$imageColumns = ['blog_image1', 'blog_image2', 'blog_image3'];
foreach ($imageColumns as $imageColumn) {
if (isset($_FILES[$imageColumn]) && $_FILES[$imageColumn]['error'] === UPLOAD_ERR_OK) {
$tempFile = $_FILES[$imageColumn]['tmp_name'];
$imageData = file_get_contents($tempFile);
$imageData = base64_encode($imageData);
$stmt = $conn->prepare("UPDATE blogs SET $imageColumn = ? WHERE bl_id = ?");
$stmt->bind_param("si", $imageData, $blogId);
$stmt->execute();
}
}
$stmt->close();
$conn->close();
header("Location: ad_blog.php");
exit();
}
}
?>
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" href="./images/site_icon.png" type="image/x-icon" />
<title>Serene Beauty | Admin-Blogs </title>
<link rel="stylesheet" href="css\a_blog.css">
<!-- <link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Poppins:wght@100;300;400;600;700&display=swap" rel="stylesheet">
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.0.7/css/all.css">
<script src="logic.js"></script> -->
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Poppins:wght@100;300;400;600;700&display=swap"
rel="stylesheet">
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.0.7/css/all.css">
<link href="https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;500;600;700&display=swap" rel="stylesheet">
<style>
.header-home {
min-height: 100vh;
width: 101%;
background-image: linear-gradient(rgba(0, 0, 0, 0.4), rgba(0, 0, 0, 0.4)), url(images/ad_ser.jpg);
background-position: center;
background-size: cover;
position: relative;
overflow-x: hidden;
}
</style>
</head>
<body>
<section class="header-home">
<nav>
<a href="index2.php"><img src="images/logo-white.png" alt=""></a>
<div class="nav-links" id="navlinks">
<i class="fa fa-times" onclick="hideMenu()"></i>
<ul>
<li><a href="ad_services.php">SERVICES</a></li>
<li><a href="ad_blog.php">BLOGS</a></li>
<li><a href="ad_booking.php">BOOKINGS</a></li>
<?php
session_start();
if ($_SESSION['flag'] === 0) {
echo "<li><a href='signUp.html'>SIGN UP</a></li>";
echo "<li><a href='login.html'>LOG IN</a></li>";
} else {
echo "<li><a href='user_pannel.php'>USER</a></li>";
}
?>
</ul>
</div>
<i class="fa fa-bars" onclick="showMenu()"></i>
</nav>
<!-- <div class="admin-panel"> -->
<h2>BLOGS</h2>
<br>
<!-- Add Blog Form -->
<form id="add-blog-form" action="" method="post" enctype="multipart/form-data">
<h3>Add Blog</h3>
<input type="text" name="blog_name" placeholder="Blog name" required>
<input type="text" name="blog_title" placeholder="Blog Title" required>
<input type="text" name="blog_author" placeholder="Blog Author" required>
<input type="date" name="blog_date" class="date-input" placeholder="Blog Date" required>
<textarea name="blog_content" placeholder="Blog Content" required></textarea>
<input type="file" name="blog_image1" accept="image/*">
<input type="file" name="blog_image2" accept="image/*">
<input type="file" name="blog_image3" accept="image/*">
<p style="color:red">*jpeg images only*</p><br>
<button type="submit" name="submit">Add Blog</button>
</form>
<br><br><br>
<!-- Blog Table -->
</div>
</section>
<table id="blog-table">
<thead>
<tr>
<th>Title</th>
<th>Content</th>
<th>Author</th>
<th>Date</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<!-- Rows will be dynamically added/updated via JavaScript -->
<?php
$conn = new mysqli("sql100.infinityfree.com", "if0_34678114", "943Uw88q1QdrSMC","if0_34678114_serenebeauty") or die("Connect failed: %s\n" . $conn->error);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['delete_id'])) {
$delete_id = $_POST['delete_id'];
$sql_delete = "DELETE FROM blogs WHERE bl_id = '$delete_id'";
if ($conn->query($sql_delete) === TRUE) {
header("Location: ad_blog.php");
echo "Row deleted successfully.";
} else {
echo "Error deleting row: " . $conn->error;
}
}
$sql2 = "SELECT * FROM blogs";
$result = $conn->query($sql2);
if ($result->num_rows > 0) {
while ($row = $result->fetch_assoc()) {
$id = $row['bl_id'];
$name = $row['bl_name'];
$title = $row['title'];
$author = $row['author'];
$date = $row['date'];
echo '<tr>
<td>', $name, '</td>
<td class="blog-name">', $title, '</td>
<td>', $author, '</td>
<td>', $date, '</td>
<td>
<form class="btn-form" method="POST" action="">
<input type="hidden" class="delete-button" name="delete_id" value="' . $id . '">
<button type="submit" class="delete-button">Delete</button>
</form>
<br>
<form class="btn-form" method="GET" action="readblog.php">
<input type="hidden" name="bl_id" value="' . $row['bl_id'] . '">
<button type="submit" class="preview-button">Preview</button>
</form>
</td>
</tr>';
}
}
?>
</tbody>
</tbody>
</table>
<script>
var navlinks = document.getElementById("navlinks");
function showMenu() {
navlinks.style.right = "0";
}
function hideMenu() {
navlinks.style.right = "-200px";
}
</script>
</body>
</html>