Dash-Da-Dash-DX-2023-Fan-Pa.../input_ddd_scoreboard.php

60 lines
1.7 KiB
PHP
Executable File

<?php
echo file_get_contents("ddd_source.html");
// Parse the config file
$config = parse_ini_file('config.cfg', true);
// Check if the [options] section and database entry exist
if (isset($config['options']) && isset($config['options']['database'])) {
$database = $config['options']['database'];
if ($database === 'mysql') {
// Include the MySQL connection script from the config file
include($config['mysql']['mysqlconnect_path']);
} elseif ($database === 'sqlite') {
// Code for SQLite
$db_path = 'db/ddd_db.sqlite';
$db = new SQLite3($db_path);
} else {
echo "Unsupported database type specified in config.cfg\n";
}
} else {
echo "Database configuration not found in config.cfg\n";
}
$b64 = $_POST["gamePass"];
$decode = base64_decode($b64, true);
$dataArr = explode("|", $decode);
$name = $dataArr[0];
$score = $dataArr[1];
$mode = $dataArr[2];
// Retrieve the boss names dynamically
$bosses = array_slice($dataArr, 3);
// Join the boss names into a single string separated by commas
$bossNames = implode(", ", $bosses);
echo $name . "<br>" . $score . "<br>" . $mode . "<br>";
echo "Bosses: " . $bossNames . "<br>";
// Prepare an SQL statement
$stmt = $db->prepare("INSERT INTO scores (Name, Score, Mode, Bosses) VALUES (?, ?, ?, ?)");
$stmt->bindValue(1, $name, SQLITE3_TEXT);
$stmt->bindValue(2, $score, SQLITE3_INTEGER);
$stmt->bindValue(3, $mode, SQLITE3_TEXT);
$stmt->bindValue(4, $bossNames, SQLITE3_TEXT);
// Execute the statement
if ($stmt->execute()) {
echo "New record created successfully";
} else {
echo "Error: " . $db->lastErrorMsg();
}
$stmt->close();
$db->close();
?>
<br>
<a class='ddd' href='ddd_index.php'>Back</a>