-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgameCreate.php
134 lines (123 loc) · 4.24 KB
/
gameCreate.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
<?php
require_once 'includes/session_timeout.php';
require_once 'includes/connection.php';
$user = $_SESSION['username'];
$conn = dbConnect('read');
$stmt = $conn->stmt_init();
$sql = 'SELECT userId FROM creator WHERE username=?';
if ($stmt->prepare($sql)) {
$stmt->bind_param('s', $user);
$stmt->execute();
$result = mysqli_stmt_get_result($stmt);
}
if (!$result) {
$error = $conn->error;
} else {
$row = $result->fetch_assoc();
$userId = $row['userId'];
$_SESSION['userId'] = $userId;
}
$sql = 'SELECT boardId, title FROM board WHERE userId=?';
if ($stmt->prepare($sql)) {
$stmt->bind_param('i', $userId);
$stmt->execute();
$boards = mysqli_stmt_get_result($stmt);
$myBoards = $boards;
}
if (!$boards) {
$error = $conn->error;
} else {
$numRows = $boards->num_rows;
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>CITY Jeopardy</title>
<link rel="stylesheet" href="styles/mystyle.css">
</head>
<body>
<header id="header" class="group" role="banner">
<a href="homelogged.php" title="Return to the front page">
<img src="images/CITY-College-Sheffield.jpg" alt="CITY Jeopardy" />
</a>
<p id="motto">Welcome to <span class="logo">CITY Jeopardy!</span><br>The fun way to learn</p>
<ul>
<li>
<?php
if (isset($_SESSION['authenticated']));
?>
<p><b>Username:</b>
<?php
echo $_SESSION['username'];
include 'includes/logout.php';
?>
</p>
</li>
</ul>
</header>
<?php
if (isset($error)) {
echo "<p>$error</p>";
} else {
switch($numRows) {
case 0: ?>
<p id="noBoards" class="warning">There are no boards. Please create a board first.</p>
<?php break;
case $numRows > 0: ?>
<div class="create">
<form method="post" action="game.php">
<ul>
<li class="form-row">
<p>Choose a board and the number of teams</p>
</li>
<li class="form-row">
<select name="boards" id="boards">
<option value="">Select a board</option>
<?php
while ($row = $myBoards->fetch_assoc()) { ?>
<option value="<?= $row['boardId']; ?>"><?= $row['title']; ?></option>
<?php } ?>
</select>
</li>
<li class="form-row">
<select name="teams" id="teamNum">
<option value="">Select number of teams</option>
<?php for ($i = 0; $i <= 10; $i++) : ?>
<option value="<?php echo $i; ?>"><?php echo $i; ?></option>
<?php endfor; ?>
</select>
</li>
<li class="form-row">
<input type="submit" name="create" value="Create Game" onclick="return empty()">
</li>
</ul>
</form>
</div>
<?php break;
} } ?>
<footer id="footer" role="contentinfo">
<ul>
<li>
<a href="boardCreate.php" title="Create a board">Create a board</a>
</li>
<li>
<a href="#" title="About">About</a>
</li>
</ul>
</footer>
<script type="text/javascript">
function empty() {
var boardSelect;
var teamSelect;
boardSelect = document.getElementById("boards").value;
teamSelect = document.getElementById("teamNum").value;
if ((boardSelect == '') || (teamSelect == '')) {
alert("Please select a value for both fields");
return false;
}
}
</script>
</body>
</html>