-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathadmincommand.php
48 lines (42 loc) · 1.67 KB
/
admincommand.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
<?php
session_start();
if ($_SESSION["isadmin"] == true) { // Make sure we have admin permissions
if ($_SERVER["REQUEST_METHOD"] == "POST") { // Make sure the request is a POST
$servername = "127.0.0.1";
$username = "secretVote";
$password = "test";
$dbname = "voting";
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die("Connection failed: ");
} else {
if (!empty($_POST["command"])) { // Check to see if the command field is even there
$command = $_POST["command"];
$sql = "";
switch ($command) {
case "stopvote":
$sql = "DELETE FROM current_poll WHERE 1=1;"; // Delete the current poll to stop voting
break;
case "startvote":
if (!empty($_POST["name"])) {
$name = $_POST["name"];
$sql = "INSERT INTO current_poll VALUES (1,'".mysqli_real_escape_string($conn, $name)."');"; // Start a poll by inserting into current_poll
}
break;
case "clearvotes":
$sql="DELETE FROM votes WHERE 1=1;";
break;
default:
break;
}
// Run the command if the switch found an actual command
if (!empty($sql)) {
$conn->query($sql);
}
}
}
}
}
// Redirect back to main admin page
Header("Location: admin.php");
?>