Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $servername = "localhost";
- $username = "root";
- $password = "";
- $dbname = "guess_the_character";
- $conn = new mysqli($servername, $username, $password, $dbname);
- // if ($conn->connect_error) {
- // die("Connection failed: " . $conn->connect_error);
- if (isset($_POST["answer"])) {
- $sql = "SELECT * FROM characters WHERE CharacterID=" . $_GET["cid"];
- $result = $conn->query($sql);
- if ($_POST["answer"]==$result[0]["CharacterName"])
- echo "You won!";
- else
- {
- }
- }
- else if (!isset($_GET["cid"]))
- {
- $sql = "SELECT CharacterID FROM characters ORDER BY RAND() LIMIT 1";
- $result = $conn->query($sql);
- $row = $result->fetch_array(MYSQLI_ASSOC);
- $id = $result[0]["CharacterID"];
- $sql = "SELECT * FROM hints WHERE characters.CharacterID=hints.CharacterID LIMIT 3";
- $result = $conn->query($sql);
- $hints = [];
- while ($row = $result->fetch_array(MYSQLI_ASSOC))
- {
- $hints[] = $row;
- }
- }
- else
- {
- $sql = "SELECT * FROM hints WHERE characters.CharacterID=hints.CharacterID and hints.CharacterID > " . $_GET["hid"]. "LIMIT 1";
- $result = $conn->query($sql);
- if (count($result) == 0) {echo "Oops, we have no more hints left for you! Try to guess the character by the hints that are already given.";
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement