예제 #1
0
<?php

session_start();
require_once "../private/db_connection.php";
require_once "../private/functions.php";
global $connection;
$id = (int) $_SESSION["id"];
$game_id = (int) $_SESSION["game_id"];
$gameover = $_GET["gameover"];
$query = "DELETE FROM player ";
$query .= "WHERE id = {$id} ";
$query .= "LIMIT 1";
$result1 = mysqli_query($connection, $query);
$all_games = find_all_games();
//is actually finding all players with games, not all games
$delete_game = true;
if ($all_games !== null) {
    while ($game = mysqli_fetch_assoc($all_games)) {
        if ($game["game_id"] == $game_id) {
            //if there is a player with this game id still existing, don't delete the game yet
            $delete_game = false;
        }
    }
}
if ($delete_game == true) {
    $query = "DELETE FROM game ";
    $query .= "WHERE game_id = {$game_id} ";
    $query .= "LIMIT 1";
    $result2 = mysqli_query($connection, $query);
}
$_SESSION["id"] = null;
예제 #2
0
파일: game.php 프로젝트: nprimak/hnefatafl
<?php

session_start();
require_once "../private/db_connection.php";
require_once "../private/functions.php";
$player_needed = false;
$game_data = find_all_games();
while ($game = mysqli_fetch_assoc($game_data)) {
    if ($game_id != $game["game_id"]) {
        $game_id = $game["game_id"];
        $player_needed = true;
    } else {
        $player_needed = false;
    }
}
if ($player_needed == true) {
    //header("refresh: 1;");
}
$game_id = $_SESSION["game_id"];
$id = $_SESSION["id"];
$turn = "black";
if ($id == null || $game_id == null) {
    redirect_to("../../home.html");
}
$game_exists = fetch_game($game_id);
if ($game_exists === null) {
    global $connection;
    $query = "INSERT INTO game (";
    $query .= " game_id, move1_row, move1_column, move2_row, move2_column, black_turn ";
    $query .= ") VALUES (";
    $query .= " {$game_id}, null, null, null, null, 1 ";