-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
141 lines (129 loc) · 3.95 KB
/
index.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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
<?php
include_once("connection.php");
$players_query = "";
if (isset($_GET["searchPlayer"]) && $_GET["searchPlayer"] != "") {
// Update enemy name and location
$sql = "SELECT player_id, name FROM Players WHERE name = ?;";
$stmt = mysqli_stmt_init($connection);
mysqli_stmt_prepare($stmt, $sql);
mysqli_stmt_bind_param($stmt, "s", $_GET["searchPlayer"]);
mysqli_stmt_execute($stmt);
$players_query = $stmt->get_result();
mysqli_stmt_close($stmt);
}
else {
$sql = "SELECT player_id, name FROM Players";
$players_query = mysqli_query($connection, $sql);
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Players</title>
<style>
body {
display: flex;
justify-content: center;
align-items: center;
}
h1 {
text-align: center;
}
table {
width: 100%;
border-collapse: collapse;
font-size: 24px;
}
th, td {
border: 2px solid black;
padding: 12px;
text-align: left;
}
th {
background-color: orange;
}
form {
margin-bottom: 20px;
text-align: center;
}
.btn {
padding: 10px 20px;
background-color: blue;
color: white;
border: none;
cursor: pointer;
border-radius: 5px;
text-align: center;
}
.btn:hover {
background-color: blue;
}
#PlayGame {
margin-top: 20px;
display: block;
margin-left: auto;
margin-right: auto;
}
#GameAdmin {
margin-top: 20px;
display: block;
margin-left: auto;
margin-right: auto;
}
#searchPlayer {
width: 300px;
padding: 10px;
border: 2px solid black;
border-radius: 5px;
box-sizing: border-box;
margin-top: 10px;
font-size: 18px;
}
a {
color: inherit;
text-decoration: none;
}
</style>
</head>
<body>
<div>
<h1>Players</h1>
<form id="playerForm">
<div style="text-align: center;">
<button type="button" class="btn" id="addPlayerBtn" onclick="window.location.href='add_player.php';">Add Player</button>
</div>
<div style="text-align: center; margin-top: 10px;">
<input type="text" id="searchPlayer" name="searchPlayer" placeholder="Search Player by Name">
<button type="button" class="btn" id="searchButton" onclick="window.location.href='index.php?searchPlayer=' + document.getElementById('searchPlayer').value;">Search</button>
</div>
</form>
<table>
<thead>
<tr>
<th>Name</th>
<th>Delete</th>
<th>Edit</th>
</tr>
</thead>
<tbody id="currentPlayers">
<?php
while ($player = mysqli_fetch_assoc($players_query)) { ?>
<tr>
<td><?php echo $player["name"]; ?></td>
<form action="./database.php" method="post">
<input name="player_id" value="<?php echo $player["player_id"]; ?>" type="hidden">
<td><button type="submit" name="deletePlayer" class="btn">Delete</button></td>
</form>
<td><a href="edit_player.php?id=<?php echo $player["player_id"];?>"><button class="btn">Edit</button></a></td>
</tr> <?php
}
?>
</tbody>
</table>
<button type="button" class="btn" id="PlayGame" onclick="window.location.href='play.html';">Play Game</button>
<button type="button" class="btn" id="GameAdmin" onclick="window.location.href='admin.php';">Login as Game Admin</button>
</div>
</body>
</html>