-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsubmit_blog_post.php
More file actions
41 lines (33 loc) · 1.14 KB
/
submit_blog_post.php
File metadata and controls
41 lines (33 loc) · 1.14 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
<?php
session_start();
include "config.php";
// Ensure the user is logged in
if (!isset($_SESSION["username"])) {
exit("You are not logged in");
}
if ($_SERVER["REQUEST_METHOD"] == "POST") {
// Get the blog post data from the form
$creator = $_SESSION["username"]; // The logged-in user's username
$message = $_POST["message"];
// Initialize the image upload variables
// Prepare the SQL statement for inserting the blog post into the database
$sql =
"INSERT INTO blog (creator, message, timestamp) VALUES (?, ?, NOW())";
// Initialize a prepared statement
if ($stmt = $conn->prepare($sql)) {
// Bind the parameters to the SQL query
$stmt->bind_param("ss", $creator, $message); // "sss" means three strings
// Execute the prepared statement
if ($stmt->execute()) {
echo "Post submitted successfully!";
} else {
echo "Error: " . $stmt->error;
}
// Close the prepared statement
$stmt->close();
} else {
echo "Error preparing statement: " . $conn->error;
}
// Close the database connection
$conn->close();
}