-
Notifications
You must be signed in to change notification settings - Fork 0
/
create_event.php
118 lines (94 loc) · 3.54 KB
/
create_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
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
<?php
session_start();
if (!isset($_SESSION["user_id"])) {
header("Location: login.php");
exit;
}
include 'db_connect.php';
$successMessage = ""; // Initialize the success message as an empty string
if ($_SERVER["REQUEST_METHOD"] === "POST") {
$userId = $_SESSION["user_id"];
$title = $_POST["title"];
$description = $_POST["description"];
$eventDate = $_POST["event_date"];
$phone_number = $_POST["phone_number"];
$email_id = $_POST["email_id"];
// Check if the selected date is in the past
$today = date("Y-m-d");
if ($eventDate < $today) {
$successMessage = "You cannot select a date in the past.";
} else {
// Handle file upload
$imagePath = ""; // Initialize the image path to an empty string
if ($_FILES["image"]["name"]) {
$imageDir = "uploads/"; // Directory where the images will be stored
$imagePath = $imageDir . $_FILES["image"]["name"];
move_uploaded_file($_FILES["image"]["tmp_name"], $imagePath);
}
// Insert event data into the database, including the image path, phone number, and email ID
$query = "INSERT INTO events (user_id, title, description, event_date, image, phone_number, email_id) VALUES (?, ?, ?, ?, ?, ?, ?)";
$stmt = $pdo->prepare($query);
$stmt->execute([$userId, $title, $description, $eventDate, $imagePath, $phone_number, $email_id]);
// Display a success message as an alert and redirect to home.php
if (!empty($successMessage)) {
echo '<script>alert("Event created successfully!");</script>';
echo '<script>window.location.href = "home.php";</script>';
}
}
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Create Event</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/water.css@2/out/water.min.css" />
<style>
body {
display: flex;
justify-content: center;
align-items: center;
flex-direction: column;
background: linear-gradient(45deg, #f0f0f0, #3498db, #f0f0f0, #3498db);
background-size: 400% 400%;
animation: gradientAnimation 5s infinite;
}
@keyframes gradientAnimation {
0% {
background-position: 0% 50%;
}
50% {
background-position: 100% 50%;
}
100% {
background-position: 0% 50%;
}
}
/* Your other CSS styles here */
</style>
</head>
<body>
<h1>Create an Event</h1>
<form method="post" action="create_event.php" enctype="multipart/form-data">
<label for="title">Title:</label>
<input type="text" name="title" required><br>
<label for="description">Description:</label>
<textarea name="description" required></textarea><br>
<label for="event_date">Event Date:</label>
<input type="date" name="event_date" required><br>
<label for="phone_number">Phone Number:</label>
<input type="text" name="phone_number" required><br>
<label for="email_id">Email ID:</label>
<input type="email" name="email_id" required><br>
<label for="image">Event Image:</label>
<input type="file" name="image"><br>
<input type="submit" value="Create Event">
<a href="home.php">Cancel</a>
</form>
<!-- Display the success message -->
<?php
if (!empty($successMessage)) {
echo '<p style="color: green;">' . $successMessage . '</p>';
}
?>
</body>
</html>