View sourcecode

The following files exists in this folder. Click to view.

match_create.php

57 lines ASCII Windows (CRLF)
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
<?php
require "auth.php";
require 
"database.php";
requireLogin();

$ladderID $_GET["ladder_id"];
$playerID $_SESSION["player_id"];

// get players in the ladder
$stmt $conn->prepare("
    SELECT p.PlayerID, p.Username
    FROM LadderPlayers lp
    JOIN Players p ON lp.PlayerID = p.PlayerID
    WHERE lp.LadderID = ?
"
);
$stmt->execute([$ladderID]);
$players $stmt->fetchAll();
?>
<!DOCTYPE html>
<html>
<head>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
<div class="container mt-5">
<h2>Submit Match</h2>

<form method="POST" action="match.php">
<input type="hidden" name="ladder_id" value="<?= $ladderID ?>">

<div class="mb-2">
<label>Opponent</label>
<select name="opponent_id" class="form-control" required>
<?php foreach ($players as $p): ?>
    <?php if ($p["PlayerID"] != $playerID): ?>
        <option value="<?= $p["PlayerID"?>">
            <?= htmlspecialchars($p["Username"]) ?>
        </option>
    <?php endif; ?>
<?php 
endforeach; ?>
</select>
</div>

<div class="mb-2">
<label>Winner</label>
<select name="winner_id" class="form-control" required>
    <option value="<?= $playerID ?>">You</option>
</select>
</div>

<button class="btn btn-primary">Submit Match</button>
<a href="ladder.php?id=<?= $ladderID ?>" class="btn btn-secondary">Cancel</a>
</form>
</div>
</body>
</html>