View sourcecode

The following files exists in this folder. Click to view.

join_ladder.php

44 lines UTF-8 Unix (LF)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<?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();
?>