Repository navigation
Expand file tree
/
Copy pathplayers.php
More file actions
205 lines (201 loc) · 6.61 KB
/
Copy pathplayers.php
File metadata and controls
205 lines (201 loc) · 6.61 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
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
<!DOCTYPE html>
<html lang="en">
<head>
<link rel="shortcut icon" href="favicon.ico" type="image/x-icon" />
<title> Players - Spikeball Information System</title>
<meta charset="utf-8">
<link rel="stylesheet" href="roundnet.css">
</head>
<div id="wrapper">
<header id="center">
<a href="index.php"><img src="roundnet.jpg" alt="roundnet logo" height="200" width="200"></a><h1>Roundnet @ WMU</h1>
</header>
<nav>
<a href="index.php" class="button">Dashboard</a>
<a href="players.php" class="button">Players</a>
<a href="attendance.php" class="button">Attendance</a>
<a href="forms.php" class="button">Form Lookup</a>
</nav>
<body id="wrapper">
<br><br><br>
<center>
<div class="darkPanel">
<form action="#" method ="post">
First Name:<input type="text" name="first_name" class="name">
Middle Initial:<input type="text" name="middle_initial" class="middleinit">
Last Name:<input type="text" name="last_name" class="name">
Age:<input type="text" name="age" class="age"> <br><br>
Email:<input type="text" name="email" class="email">
Western ID Number(WIN):<input type="text" name="win" class="email">
<br>
<br>
Playstyle:<br>
<input type="radio" name="playstyle" value="Casual">Casual
<input type="radio" name="playstyle" value="Hardcore">Hardcore
<br><br>
Phone Number:<input type="text" name="phone" class="email">
<br><br>
Forms Submitted:<br>
<input type="radio" name="forms" value="Not Submitted">Not Submitted
<input type="radio" name="forms" value="Submitted">Submitted
<br><br>
<input type="submit" name="submit" value="Add Player" class="submitButton">
<input type="submit" value="Clear Data" name="clear" class="submitButton">
<br>
<br>
<input type="submit" value="Show Ascending" name="ascend" class="submitButton">
<input type="submit" value="Show Descending" name="descend" class="submitButton">
<br>
<br>
<br>
</form>
</div>
<br>
<?php
/*Login to mySQL db*/
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "roundnet";
$tabledisplayed = false;
$conn = mysqli_connect($servername, $username, $password, $dbname); //Connect to mySQL db
if($conn->connect_error){
die("Connection Failed: " . mysqli_connect_error()); //If connection fails, output the error
}
if(isset($_POST['submit'])){
/*Use mysqli_real_escape_string function to avoid SQL Injection security issues.*/
$first_name = mysqli_real_escape_string($conn,$_POST['first_name']);
$middle_initial = mysqli_real_escape_string($conn,$_POST['middle_initial']);
$last_name = mysqli_real_escape_string($conn,$_POST['last_name']);
$age = mysqli_real_escape_string($conn,$_POST['age']);
$email = mysqli_real_escape_string($conn,$_POST['email']);
$win = mysqli_real_escape_string($conn,$_POST['win']);
$playstyle = mysqli_real_escape_string($conn,$_POST['playstyle']);
$phone = mysqli_real_escape_string($conn,$_POST['phone']);
$forms = mysqli_real_escape_string($conn,$_POST['forms']);
/*Insert data into table*/
$sql = "INSERT INTO players (first_name,middle_initial,last_name,age,email,win,playstyle,phone,forms)
VALUES('$first_name','$middle_initial','$last_name','$age','$email','$win','$playstyle','$phone','$forms');";
if($conn->query($sql) === True){
echo "Data has been written successfully";
}
else{
echo "<script>alert(Error: $conn->error);</script>";
}
}
if (isset($_POST['ascend'])){ //Sorts table in ascending order by WIN
$tabledisplayed = true;
$sql = "SELECT * FROM players ORDER BY win asc";
$result = $conn->query($sql);
if (mysqli_num_rows($result) > 0) {
// output data of each row
echo "<table>
<tr>
<th>First Name</th>
<th>Middle Initial</th>
<th>Last Name</th>
<th>WIN</th>
<th>Age</th>
<th>Email</th>
<th>Playstyle</th>
<th>Phone</th>
<th>Forms</th>
</tr>";
while($row = mysqli_fetch_assoc($result)) {
echo "<tr>
<td>" . $row["first_name"]. "</td>
<td>" . $row["middle_initial"]. "</td>
<td>" . $row["last_name"]. "</td>
<td>" . $row["win"]. "</td>
<td>" . $row["age"]. "</td>
<td>" . $row["email"]. "</td>
<td>" . $row["playstyle"]. "</td>
<td>" . $row["phone"]. "</td>
<td>" . $row["forms"]. "</td>
</tr>";
}
echo "</table>";
} else {
echo "0 results";
}
}
if (isset($_POST['descend'])){ //Sorts table in descending order by WIN
$tabledisplayed = true;
$sql = "SELECT * FROM players ORDER BY win desc";
$result = $conn->query($sql);
if (mysqli_num_rows($result) > 0) {
// output data of each row
echo "<table>
<tr>
<th>First Name</th>
<th>Middle Initial</th>
<th>Last Name</th>
<th>WIN</th>
<th>Age</th>
<th>Email</th>
<th>Playstyle</th>
<th>Phone</th>
<th>Forms</th>
</tr>";
while($row = mysqli_fetch_assoc($result)) {
echo "<tr>
<td>" . $row["first_name"]. "</td>
<td>" . $row["middle_initial"]. "</td>
<td>" . $row["last_name"]. "</td>
<td>" . $row["win"]. "</td>
<td>" . $row["age"]. "</td>
<td>" . $row["email"]. "</td>
<td>" . $row["playstyle"]. "</td>
<td>" . $row["phone"]. "</td>
<td>" . $row["forms"]. "</td>
</tr>";
}
echo "</table>";
} else {
echo "0 results";
}
}
/*Selectively delete data from table*/
if (isset($_POST['clear'])){
$win = mysqli_real_escape_string($conn,$_POST['win']);
$sql = "DELETE FROM players WHERE win='$win'";
if($conn->query($sql) === True){
echo "Data deleted successfully.";
}
else{
echo "Error deleting data from table: " . $conn->error;
}}
/*Selectively edit data from table*/
if (isset($_POST['edit'])){
$win = mysqli_real_escape_string($conn,$_POST['win']);
$sql = "SELECT FROM players WHERE win='$win'";
if (!$_POST['first_name'] == $row["first_name"])
{$row["first_name"] = $_POST['first_name'];}
if (!$_POST['middle_initial'] == $row["middle_initial"])
{$row["middle_initial"] = $_POST['middle_initial'];}
if (!$_POST['last_name'] == $row["last_name"])
{$row["last_name"] = $_POST['last_name'];}
if (!$_POST['win'] == $row["win"])
{$row["win"] = $_POST['win'];}
if (!$_POST['age'] == $row["age"])
{$row["age"] = $_POST['age'];}
if (!$_POST['email'] == $row["email"])
{$row["email"] = $_POST['email'];}
if (!$_POST['playstyle'] == $row["playstyle"])
{$row["playstyle"] = $_POST['playstyle'];}
if (!$_POST['phone'] == $row["phone"])
{$row["phone"] = $_POST['phone'];}
if (!$_POST['forms'] == $row["forms"])
{$row["forms"] = $_POST['forms'];}
if($conn->query($sql) === True){
echo "Data altered successfully.";
}
else{
echo "Error altering data in table: " . $conn->error;
}}
?>
</center>
</body>
</div>
</html>