The following files exists in this folder. Click to view.
join_ladder.php44 lines UTF-8 Unix (LF)
<?php
session_start();
require_once('databaseconnection.php');
include('functions.php');
include('check_login.php');
$sql = "SELECT ladderId, playerroof FROM Ladders
WHERE code = :code";
$stm = $pdo->prepare($sql);
$stm->execute([':code' => $_POST['code'],]);
$res = $stm->fetch(PDO::FETCH_ASSOC);
//Kollar så att inte stegen är full
if (isset($res['playerroof']) && $res['playerroof'] <= playercount($res['ladderId'])){
header('location: home.php');
exit();
}
if (isset($res['ladderId'])){
$sql = "SELECT userId FROM Players
WHERE userId = :userId AND ladderId = :ladderId"; //Kollar så att inte användaren finns i stegen
$stm = $pdo->prepare($sql);
$stm->execute([':userId' => $_SESSION['userId'], ':ladderId' => $res['ladderId']]);
$check = $stm->fetch(PDO::FETCH_ASSOC);
if (isset($check['userId'])){
echo "already in";
header('location: home.php');
exit();
}
//Lägger in användaren i stegen
$sql = "INSERT INTO Players (userId, ladderId)
VALUES (:userId, :ladderId);";
$stm = $pdo->prepare($sql);
$stm->execute([
':userId' => $_SESSION['userId'],
':ladderId' => $res['ladderId']
]);
echo "inserted";
header('location: home.php');
exit();
}
header('location: home.php');
exit();
?>