Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html lang="en">
- <?php
- session_start();
- $temp = isset($_SESSION["password"]);
- $_SESSION["password"] = md5($temp);
- ?>
- <head>
- <meta charset="UTF-8">
- <title>Match Counter!</title>
- </head>
- <body>
- <div id="wins">
- <?php
- $servername = "devweb2017.cis.strath.ac.uk";
- $username = "ywb16155";
- $passwordDB = "xAtYbFaLTKjTGPtj";
- $database = "ywb16155";
- $conn = new mysqli($servername, $username, $passwordDB, $database);
- if (isset($_POST["password"])) {
- $_SESSION["password"] = $_POST["password"];
- }
- if ($conn -> connect_error){
- die ("connection failed ". mysqli_connect_error()); //remove once debugged
- }
- $sql = "SELECT * FROM `tennisCoaches`";
- $result = $conn->query($sql);
- $serverPass ="";
- if ($result->num_rows > 0) {
- while ($row = $result->fetch_assoc()) {
- $serverPass = $row["password"];
- }
- }
- if (md5($_SESSION["password"]) != $serverPass) {
- ?>
- <div>
- <h4>Please login if you are a coach.</h4>
- <form action="coach.php" method="POST">
- <p>
- Password: <input type="text" name="password" value=""/>
- </p>
- <p>
- <input type="submit" value="login"/>
- </p>
- </form>
- </div>
- <?php
- }else{
- $sql = "SELECT * FROM `tennisPlayers`;";
- $result = $conn->query($sql);
- if (!$result) {
- die("Query broke!" . $conn->error);
- }
- if ($result->num_rows > 0){
- echo "<h3>Number of wins </h3>";
- ?>
- <table>
- <tr>
- <th>Player</th>
- <th>Wins</th>
- <br>
- </tr>
- <?php
- while ($row = $result->fetch_assoc()) {
- ?>
- <tr>
- <td><?php echo $row["name"] ?></td>
- <td><?php echo $row["wins"] ?><br></td>
- </tr>
- <?php
- }
- ?>
- </table>
- </div>
- <div id="played">
- <?php
- }
- $sql = "SELECT * FROM `tennisGames`;";
- $result = $conn->query($sql);
- if ($result->num_rows > 0){
- echo "<h3>Games Played</h3>";
- ?>
- <table>
- <?php
- while ($row = $result->fetch_assoc()) {
- if (($row["player1score"] > 0) || ($row["player2score"] > 0)) {
- ?>
- <tr>
- <td><?php echo $row["player1"] ?></td>
- <td><?php echo $row["player1score"] ?></td>
- V
- <td><?php echo $row["player2"] ?></td>
- <td><?php echo $row["player2score"] ?><br></td>
- <button> </button>
- </tr>
- <?php
- }
- }
- ?>
- </table>
- </div>
- <div id="waiting">
- <?php
- }
- $sql = "SELECT * FROM `tennisGames`;";
- $result = $conn->query($sql);
- if ($result->num_rows > 0){
- echo "<h3>Games to be Played</h3>";
- ?>
- <table>
- <?php
- while ($row = $result->fetch_assoc()) {
- if (($row["player1score"] == 0) && ($row["player2score"] == 0)) {
- ?>
- <tr>
- <td><?php echo $row["player1"] ?></td>
- <td> V</td>
- <td><?php echo $row["player2"] ?><br></td>
- </tr>
- <?php
- }
- }
- }
- ?>
- </table>
- </div>
- <div id="update">
- <form action="coach.php" method="post">
- <?php
- echo "<br>";
- echo "<h3> Update the tables!</h3>";
- $sql = "SELECT * FROM `tennisPlayers`;";
- $result = $conn->query($sql);
- if ($result->num_rows > 0) {
- echo "<select name=\"first\">\n";
- while ($row = $result->fetch_assoc()) {
- echo "<option value=\"" . $row["id"] . "\">" . $row["name"] . "</option>";
- }
- echo "<select>\n";
- }
- echo "<input type=\"number\" min = 0 max = 6 name=\"score1\" value = \"0\"/>";
- echo " V ";
- echo "<input type=\"number\" min = 0 max = 6 name=\"score2\" value = \"0\"/>";
- $result = $conn->query($sql);
- if ($result->num_rows > 0) {
- echo "<select name=\"second\">\n";
- while ($row = $result->fetch_assoc()) {
- echo "<option value=\"" . $row["id"] . "\">" . $row["name"] . "</option>";
- }
- echo "<select>\n";
- }
- echo "<br>";
- ?>
- <p>
- <input type="submit" name="setScores" value="amend"/>
- </p>
- </form>
- </div>
- <?php
- if (isset($_REQUEST["setScores"])) {
- $id1 = $_POST["first"];
- $id2 = $_POST["second"];
- $score1 = strip_tags(isset($_POST["score1"]) ? $_POST["score1"] : "");
- $score2 = strip_tags(isset($_POST["score2"]) ? $_POST["score2"] : "");
- $sql = "SELECT `name` FROM `tennisPlayers` WHERE `id` = '$id1' ;";
- $result = $conn->query($sql);
- $temp = $result->fetch_assoc();
- $name1 = mysqli_real_escape_string($conn, strip_tags($temp["name"]));
- $sql = "SELECT `name` FROM `tennisPlayers` WHERE `id` = '$id2' ;";
- $result = $conn->query($sql);
- $temp = $result->fetch_assoc();
- $name2 = mysqli_real_escape_string($conn, strip_tags($temp["name"]));
- $sql = "SELECT `gameID` FROM `tennisGames` WHERE `player1` = '$name1' && `player2` = '$name2';";
- $result = $conn->query($sql);
- $temp = $result->fetch_assoc();
- $gameID = $temp["gameID"];
- $sql = "UPDATE `tennisGames` SET `player1score`='$score1',`player2score`='$score2'
- WHERE `gameID` = '$gameID';";
- $conn->query($sql);
- if (($conn->query($sql) === TRUE) && ($id1 != $id2)) {
- echo "<p>Scores successfully entered.</p>";
- } else {
- echo "<p>Scores not entered successfully.</p>";
- }
- if ($score1 > $score2) {
- $sql = "UPDATE `tennisPlayers` SET `wins`= `wins` + 1 WHERE `id` = '$id1';";
- } else {
- $sql = "UPDATE `tennisPlayers` SET `wins`= `wins` + 1 WHERE `id` = '$id2';";
- }
- if (($conn->query($sql) === TRUE) && ($id1 != $id2)) {
- echo "<p>Player wins updated.</p>";
- }
- $conn->close();
- }
- }
- ?>
- <form action="https://devweb2017.cis.strath.ac.uk/~ywb16155/tennis_proj/index.php">
- <input type="submit" value="Go to Index" />
- </form>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement