setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); // Double-check to make sure the user isn't already in the database, i.e. if the user re-submits the form // Check if the user exists $sqlUserCheck = $conn->prepare("SELECT username FROM " . $userTableName . ""); // Execute SQL query $sqlUserCheck->execute(); // Get results from the USERS table $results = $sqlUserCheck->fetch(); // Check if user exists if (mb_strtolower($_GET["username"]) == mb_strtolower($results["username"])) { // USER ALREADY EXISTS echo "
"; echo "

Fatal error

"; echo "

Please go to the home page and try what you were doing again

"; echo "

 

"; echo "HOME"; echo "
"; } else { // USER DOES NOT EXIST // Variables for the various input fields $username = $_POST["username"]; $password = password_hash($_POST["password"], PASSWORD_DEFAULT); // Hash the password for security $discord = $_POST["discord"]; $discordLink = $_POST["discordLink"]; $twitch = $_POST["twitch"]; $youtube = $_POST["youtube"]; $youtubeLink = $_POST["youtubeLink"]; $privileges = 0; if ($_POST["administrator"] != $userInfo["privileges"]) { $privileges = 1; } else { $privileges = $userInfo["privileges"]; } if ($_POST["moderator"] != $userInfo["privileges"]) { $privileges = 2; } else { $privileges = $userInfo["privileges"]; } $insert = $conn->prepare("INSERT INTO " . $userTableName . " (username, password, discord, discordLink, twitch, youtube, youtubeLink, privileges) VALUES (:username, :password, :discord, :discordLink, :twitch, :youtube, :youtubeLink, :privileges)"); $insert->bindParam(":username", $username); $insert->bindParam(":password", $password); $insert->bindParam(":discord", $discord); $insert->bindParam(":discordLink", $discordLink); $insert->bindParam(":twitch", $twitch); $insert->bindParam(":youtube", $youtube); $insert->bindParam(":youtubeLink", $youtubeLink); $insert->bindParam(":privileges", $privileges); $insert->execute(); if ($privileges == 1) { echo "New admin user \"" . $username . "\" created successfully"; } else { echo "
"; echo "

Account created! You may sign in now.

"; echo "

 

"; echo "HOME"; echo "SIGN IN"; echo "

 

"; echo "
"; } } } catch (PDOException $e) { // failed connection echo "Connection failed: " . $e->getMessage(); } $conn = null; ?>