-
Notifications
You must be signed in to change notification settings - Fork 0
/
update.php
75 lines (61 loc) · 2.43 KB
/
update.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
<?php
$servername = "localhost";
$username = "root";
$password = "";
$database = "eventhub";
// Create a database connection
$conn = new mysqli($servername, $username, $password, $database);
// Check the connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
// Set character set to UTF-8 (optional, but recommended)
$conn->set_charset("utf8");
if (isset($_POST['update_event'])) {
// Validate event ID
$event_id = $_POST['event_id'];
if (!is_numeric($event_id)) {
echo "<script>alert('Event ID must be a number.'); window.location = 'Home.html';</script>";
exit;
}
// Validate event name
$event_name = $_POST['event_name'];
if (!preg_match("/^[a-zA-Z\s]+$/", $event_name)) {
echo "<script>alert('Event Name can only contain letters.'); window.location = 'Home.html';</script>";
exit;
}
// Validate event date
$event_date = $_POST['event_date'];
if (strtotime($event_date) < strtotime(date('Y-m-d'))) {
echo "<script>alert('Invalid event date. Please select a future date.'); window.location = 'Home.html';</script>";
exit;
}
// Validate event location and description (optional, add as needed)
// Construct the SQL query to update the record in the eventregister table
$sql = "UPDATE eventregister SET event_name = ?, event_date = ?, event_location = ?, description = ? WHERE eventid = ?";
// Prepare the SQL statement
$stmt = $conn->prepare($sql);
if ($stmt) {
// Bind the parameters
$stmt->bind_param("ssssi", $event_name, $event_date, $event_location, $event_description, $event_id);
// Execute the update
$stmt->execute();
if ($stmt->affected_rows > 0) {
// Data updated successfully
echo "<script>alert('Event Updated successfully.'); window.location = 'Home.html';</script>";
} else {
// No rows affected, possibly no matching event ID
echo "<script>alert('Event registration failed.'); window.location = 'Home.html';</script>";
}
// Close the statement
$stmt->close();
} else {
echo "<script>alert('Error on Database.'); window.location = 'Home.html';</script>";
}
} else {
// Handle the case where the form was not submitted
echo "<script>alert('Form not submitted.'); window.location = 'Home.html';</script>";
}
// Close the database connection
$conn->close();
?>