setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
echo "Connected successfully
";
// Check if the users table exists already
$sqlCheckUserTable = $conn->prepare("SHOW TABLES LIKE '" . $adminUserTableName . "'");
// Run the query
$sqlCheckUserTable->execute();
//Check if any rows exist - if not, create the table
$count = $sqlCheckUserTable->rowCount();
if ($count == 0) {
try {
$conn->query($sqlCreateAdminTable);
echo "Table '" . $adminUserTableName . "' successfully created (user data)
";
} catch (PDOException $e) {
echo $sqlCreateUserTable . "
" . $e->getMessage();
}
}
// Variables for the various input fields
$username = $_POST["username"];
$password = password_hash($_POST["password"], PASSWORD_DEFAULT); // Hash the password for security
$discord = $_POST["discord"];
$twitch = $_POST["twitch"];
$youtube = $_POST["youtube"];
$isAdmin = 0;
if (filter_has_var(INPUT_POST, "isAdmin")) {
$isAdmin = 1;
}
echo "
";
echo $username . "
";
echo $password . "
";
echo $discord . "
";
echo $twitch . "
";
echo $youtube . "
";
echo $isAdmin . "
";
$insert = $conn->prepare("INSERT INTO " . $adminUserTableName . " (username, password, discord, twitch, youtube, isAdmin) VALUES (:username, :password, :discord, :twitch, :youtube, :isAdmin)");
$insert->bindParam(":username", $username);
$insert->bindParam(":password", $password);
$insert->bindParam(":discord", $discord);
$insert->bindParam(":twitch", $twitch);
$insert->bindParam(":youtube", $youtube);
$insert->bindParam(":isAdmin", $isAdmin);
$insert->execute();
echo "New records created successfully?";
} catch (PDOException $e) { // failed connection
echo "Connection failed: " . $e->getMessage();
}
$conn = null;
?>