Advertisement
KimChoJapFan

Rock, Paper, Scissors: required.php

Sep 28th, 2016
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.44 KB | None | 0 0
  1. <?php
  2. define("DB_USER","");
  3. define("DB_PASS","");
  4. define("DB_HOST","");
  5. define("DB_BASE","");
  6. class database {
  7.     function conn(){
  8.         $conn = mysqli_connect(DB_HOST,DB_USER,DB_PASS,DB_BASE) or die("The database got shit on mate.");
  9.         return $conn;
  10.     }
  11.    
  12.     function query($conn,$passcode,$username,$result){
  13.         $que = "INSERT INTO results (username,passcode,date,result) VALUES ('".$username."','".$passcode."','".date('m-d-Y')."','".$result."')";
  14.         if($stmt = mysqli_prepare($conn,$que)) {
  15.             mysqli_stmt_execute($stmt);
  16.             mysqli_stmt_close($stmt);
  17.         }
  18.         mysqli_close($conn);
  19.         return True;
  20.     }
  21.    
  22.     function gather($conn,$passcode){
  23.         $query = "SELECT username,result FROM results WHERE passcode='".$passcode."'";
  24.         if($stmt = mysqli_prepare($conn,$query)) {
  25.             mysqli_stmt_execute($stmt);
  26.             mysqli_stmt_bind_result($stmt,$name,$res);
  27.             $cho = array();
  28.             $nam = array();
  29.             while(mysqli_stmt_fetch($stmt)) {
  30.                 $cho[] = $res;
  31.                 $nam[] = $name;
  32.             }
  33.            
  34.             if(count($cho) < 2) {
  35.                 return '<center><span style="color:rgb(120,0,0);">No Cheating Please!</span></center><br><br>';
  36.             } elseif(count($cho) > 2) {
  37.                 return '<center><span style="color:rgb(0,0,120);">This is a 2 player game for now!</span></center><br><br>';
  38.             } else {
  39.                 if((int)$cho[0] == (int)$cho[1]) {
  40.                     return '<center><span style="color:rgb(120,120,120);">TIE!</span></center><br><br>';
  41.                 } elseif(((int)$cho[0] == 1) && ((int)$cho[1] == 2)) {
  42.                     return '<center><span style="color:rgb(0,120,0);">'.$nam[1].' WINS!</span></center><br><br>';
  43.                 } elseif(((int)$cho[0] == 1) && ((int)$cho[1] == 3)) {
  44.                     return '<center><span style="color:rgb(0,120,0);">'.$nam[0].' WINS!</span></center><br><br>';
  45.                 } elseif(((int)$cho[0] == 2) && ((int)$cho[1] == 1)) {
  46.                     return '<center><span style="color:rgb(0,120,0);">'.$nam[0].' WINS!</span></center><br><br>';
  47.                 } elseif(((int)$cho[0] == 2) && ((int)$cho[1] == 3)) {
  48.                     return '<center><span style="color:rgb(0,120,0);">'.$nam[1].' WINS!</span></center><br><br>';
  49.                 } elseif(((int)$cho[0] == 3) && ((int)$cho[1] == 1)) {
  50.                     return '<center><span style="color:rgb(0,120,0);">'.$nam[1].' WINS!</span></center><br><br>';
  51.                 } elseif(((int)$cho[0] == 3) && ((int)$cho[1] == 2)) {
  52.                     return '<center><span style="color:rgb(0,120,0);">'.$nam[0].' WINS!</span></center><br><br>';
  53.                 } else {
  54.                     return False;
  55.                 }
  56.             }
  57.            
  58.             mysqli_stmt_close($stmt);
  59.         }
  60.         mysqli_close($conn);
  61.         return True;
  62.     }
  63. }
  64. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement