-
Notifications
You must be signed in to change notification settings - Fork 0
/
update-election-settings.php
53 lines (41 loc) · 1.76 KB
/
update-election-settings.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
<?php
session_start();
// Check if the user is not logged in, redirect to the login page
if (!isset($_SESSION['employeeID'])) {
header("Location: login.php");
exit();
}
// Include your database connection file
include('connection.php');
$employeeID = $_SESSION['employeeID'];
$sql = "SELECT SectionBatch FROM election_data WHERE employeeID = '$employeeID'";
$result = mysqli_query($conn, $sql);
if ($result) {
$row = mysqli_fetch_assoc($result);
// Set SectionBatch value
$SectionBatch = $row['SectionBatch'];
} else {
echo "Error: " . $sql . "<br>" . mysqli_error($conn);
}
if ($_SERVER["REQUEST_METHOD"] == "POST") {
if (isset($_POST["save"]) || isset($_POST["flexSwitchCheckDefault1"]) || isset($_POST["flexSwitchCheckDefault2"])) {
// Retrieve data from the form
$isActive = $_POST["flexSwitchCheckDefault1"] == "on" ? 1 : 0;
$isPaused = $_POST["flexSwitchCheckDefault2"] == "on" ? 1 : 0;
$showResult = $_POST["flexSwitchCheckDefault3"] == "on" ? 1 : 0;
$openForApply = $_POST["flexSwitchCheckDefault4"] == "on" ? 1 : 0;
// Perform MySQL update operation
// Sample SQL query (replace with your actual table and column names):
$sql = "UPDATE election_settings SET IsActive = '$isActive', IsPaused = '$isPaused', showResult = '$showResult', openForApply = '$openForApply' WHERE SectionBatch = '$SectionBatch'";
if (mysqli_query($conn, $sql)) {
// echo "Election settings have been updated successfully.";
header('location:dashboard.php');
} else {
echo "Error: " . $sql . "<br>" . mysqli_error($conn);
}
} else {
echo "Please fill in all the required fields.";
}
}
// Close the database connection
mysqli_close($conn);