-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathedit_event.php
61 lines (50 loc) · 1.65 KB
/
edit_event.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
<?php
session_start();
if (!isset($_SESSION["user_id"])) {
header("Location: login.php");
exit;
}
include 'db_connect.php';
$eventId = $_GET['id'];
// Check if the logged-in user is the event creator
$userId = $_SESSION["user_id"];
$query = "SELECT user_id FROM events WHERE id = ?";
$stmt = $pdo->prepare($query);
$stmt->execute([$eventId]);
$event = $stmt->fetch();
if ($event && $event['user_id'] === $userId) {
if ($_SERVER["REQUEST_METHOD"] === "POST") {
$title = $_POST["title"];
$description = $_POST["description"];
$eventDate = $_POST["event_date"];
$query = "UPDATE events SET title = ?, description = ?, event_date = ? WHERE id = ?";
$stmt = $pdo->prepare($query);
$stmt->execute([$title, $description, $eventDate, $eventId]);
header("Location: home.php");
exit;
}
$query = "SELECT * FROM events WHERE id = ?";
$stmt = $pdo->prepare($query);
$stmt->execute([$eventId]);
$event = $stmt->fetch();
} else {
header("Location: home.php");
exit;
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Edit Event</title>
</head>
<body>
<h1>Edit Event</h1>
<form method="post" action="edit_event.php?id=<?php echo $eventId; ?>">
Title: <input type="text" name="title" required value="<?php echo $event['title']; ?>"><br>
Description: <textarea name="description" required><?php echo $event['description']; ?></textarea><br>
Event Date: <input type="date" name="event_date" required value="<?php echo $event['event_date']; ?>"><br>
<input type="submit" value="Save Changes">
</form>
<a href="home.php">Back to Home</a>
</body>
</html>