diff --git a/polls/db.php b/polls/db.php new file mode 100644 index 0000000..c02894e --- /dev/null +++ b/polls/db.php @@ -0,0 +1,166 @@ +query("SELECT COUNT(*) FROM users")->fetchColumn(); + +// If at least one user exists, show a message and no form +if ($checkTotal > 0) { + ?> + + + + + Setup Admin User + + + +
+

Admin User Already Exists

+

+ An admin user has already been created. No additional admins can be set up here. +

+

+ Go back to the Polls site. +

+
+ + + prepare(" + INSERT INTO users (username, password) + VALUES (:username, :password) + "); + $insertStmt->bindValue(':username', $username, PDO::PARAM_STR); + $insertStmt->bindValue(':password', $hashedPassword, PDO::PARAM_STR); + $insertStmt->execute(); + + $success = "Admin user '$username' created successfully."; + } +} +?> + + + + + Setup Admin User + + + +
+

Setup Admin User

+ + +
+ + +
+

You can now go to the Admin page to log in.

+ +
+
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ +
+
+ +
+ +