Advertisement
Guest User

Untitled

a guest
Oct 20th, 2017
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.27 KB | None | 0 0
  1. <?php
  2. $servername = "localhost";
  3. $username = "root";
  4. $password = "";
  5. $dbname = "guess_the_character";
  6. $conn = new mysqli($servername, $username, $password, $dbname);
  7. // if ($conn->connect_error) {
  8. //     die("Connection failed: " . $conn->connect_error);
  9.  
  10. if (isset($_POST["answer"])) {
  11.     $sql = "SELECT * FROM characters WHERE CharacterID=" . $_GET["cid"];
  12.     $result = $conn->query($sql);
  13.     if ($_POST["answer"]==$result[0]["CharacterName"])
  14.     echo "You won!";
  15.     else
  16.     {
  17.  
  18.     }
  19. }
  20.  
  21.  
  22. else if (!isset($_GET["cid"]))
  23. {
  24.     $sql = "SELECT CharacterID FROM characters ORDER BY RAND() LIMIT 1";
  25.     $result = $conn->query($sql);
  26.     $row = $result->fetch_array(MYSQLI_ASSOC);
  27.  
  28.     $id = $result[0]["CharacterID"];
  29.  
  30.     $sql = "SELECT * FROM hints WHERE characters.CharacterID=hints.CharacterID LIMIT 3";
  31.     $result = $conn->query($sql);
  32.     $hints = [];
  33.     while ($row = $result->fetch_array(MYSQLI_ASSOC))
  34.     {
  35.         $hints[] = $row;
  36.     }
  37.    
  38. }
  39. else
  40. {
  41.     $sql = "SELECT * FROM hints WHERE characters.CharacterID=hints.CharacterID and hints.CharacterID > " . $_GET["hid"]. "LIMIT 1";
  42.     $result = $conn->query($sql);
  43.     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.";
  44. }
  45. }
  46. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement