pdo_article->prepare("SELECT * FROM puzzles WHERE (id == :id AND code == :code)"); $stmt->bindValue(":id", $art_id); $stmt->bindValue(":code", htmlspecialchars($_GET["code"])); $stmt->execute(); $article = $stmt->fetch(); // Recherche du groupe : $stmt = $database->pdo_teams->prepare("SELECT * FROM teams WHERE id == :id"); $stmt->bindValue(":id", $team_id); $stmt->execute(); // Vérification de l'existence du groupe, et de la combinaison ID énigme + code : if (empty($article) || empty($stmt->fetchAll())) { echo 0; } else { // On enregistre la réussite dans la table : // Vérification que ce n'est pas déjà enregistré : $stmt = $database->pdo_teams->prepare("SELECT * FROM solved WHERE (puzzle_id == :puzzle_id AND team_id == :team_id)"); $stmt->bindValue(":puzzle_id", $art_id); $stmt->bindValue(":team_id", $team_id); $stmt->execute(); // Si ce n'est pas le cas, on enregistre : if (empty($stmt->fetch())) { $stmt = $database->pdo_teams->prepare("INSERT INTO solved VALUES (:puzzle_id, :team_id)"); $stmt->bindValue(":puzzle_id", $art_id); $stmt->bindValue(":team_id", $team_id); $stmt->execute(); } $data = [ "answer" => $article["answer"], "location" => $article["location"] ]; header("Content-Type: application/json; charset=utf-8"); echo json_encode($data); } } else { header("Location: index.php"); die(); } ?>