-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinsert_player.php
More file actions
66 lines (53 loc) · 1.72 KB
/
insert_player.php
File metadata and controls
66 lines (53 loc) · 1.72 KB
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
<html>
<head><title>Game Battle System</title></head>
<body>
<h2>Add a new player!</h2>
<form action="insertplayer.php" method=post>
Player Name: <input type=text name="name" size=20><br><br>
Player ID: <input type=text name="id" size=10><br><br>
<input type=submit name="submit" value="Insert"></form>
<?php
if (isset($_COOKIE["username"])) {
$username = $_COOKIE["username"];
$password = $_COOKIE["password"];
$servername = "17carson.cs.uleth.ca";
$dbname = "zhas3660";
echo "<table style='border: solid 1px black;'>";
echo "<tr><th>[Name]</th><th>[ID]</th><th>[Score]</th><th>[Level]</th></tr>";
class TableRows extends RecursiveIteratorIterator {
function __construct($it) {
parent::__construct($it, self::LEAVES_ONLY);
}
function current() {
return "<td style='width: 150px; border: 1px solid black;'>" . parent::current(). "</td>";
}
function beginChildren() {
echo "<tr>";
}
function endChildren() {
echo "</tr>" . "\n";
}
}
try {
$conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$stmt = $conn->prepare("SELECT name, id, score, level FROM PLAYER");
$stmt->execute();
// set the resulting array to associative
$result = $stmt->setFetchMode(PDO::FETCH_ASSOC);
foreach(new TableRows(new RecursiveArrayIterator($stmt->fetchAll())) as $k=>$v) {
echo $v;
}
}
catch(PDOException $e) {
echo "Error: " . $e->getMessage();
}
$conn = null;
echo "</table>";
echo "<a href=\"main.php\">Return</a> to Home Page.";
} else {
echo "<h3>not logged in</h3><p> <a href=\"index.php\">Login First</a></p>";
}
?>
</body>
</html>