Webbserver - Love Blomberg

Show sourcecode

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

public_html/GYA2/api/

admin_data.php
complete_session.php
export_csv.php
save_maze.php
save_reaction.php
save_simon.php
start_session.php

complete_session.php

38 lines ASCII Unix (LF)
<?php
require __DIR__ '/../config.php';

header('Content-Type: application/json');

if (
$_SERVER['REQUEST_METHOD'] !== 'POST') {
    
http_response_code(405);
    echo 
json_encode(['error' => 'Method not allowed']);
    exit;
}

$data json_decode(file_get_contents('php://input'), true);

if (!
$data) {
    
http_response_code(400);
    echo 
json_encode(['error' => 'Invalid JSON']);
    exit;
}

$pid = (int)($data['participant_id'] ?? 0);

if (
$pid <= 0) {
    
http_response_code(400);
    echo 
json_encode(['error' => 'Invalid participant_id']);
    exit;
}

try {
    
$pdo getDB();
    
$stmt $pdo->prepare('UPDATE participants SET completed_at = NOW() WHERE id = :pid');
    
$stmt->execute([':pid' => $pid]);

    echo 
json_encode(['success' => true]);
} catch (
PDOException $e) {
    
http_response_code(500);
    echo 
json_encode(['error' => 'Database error']);
}