diff options
author | cflip <36554078+cflip@users.noreply.github.com> | 2021-04-24 19:40:50 -0600 |
---|---|---|
committer | cflip <36554078+cflip@users.noreply.github.com> | 2021-04-24 19:40:50 -0600 |
commit | 2098bf444afadcf0363d89b4cc1dca5d2213d754 (patch) | |
tree | da93b29e22170d7be7c9ed215fde5238e9d76178 /register.php | |
parent | aae25cd709d486f7ee9513753d40eb5cc239c42d (diff) |
Remove all uses of db_inc.php
This method of importing the database login every time wasn't very good.
Now everything uses the new Database singleton class.
Diffstat (limited to 'register.php')
-rw-r--r-- | register.php | 41 |
1 files changed, 3 insertions, 38 deletions
diff --git a/register.php b/register.php index 050878e..02fbe58 100644 --- a/register.php +++ b/register.php @@ -20,31 +20,7 @@ <br> <?php -include_once 'includes/db_inc.php'; - -function username_exists($dbc, $user_name) -{ - $sql = "SELECT * FROM users WHERE user_name = ?;"; - $stmt = mysqli_stmt_init($dbc); - - if (!mysqli_stmt_prepare($stmt, $sql)) { - die("Error: " . mysqli_error($dbc)); - } - - mysqli_stmt_bind_param($stmt, "s", $user_name); - mysqli_stmt_execute($stmt); - - $result = mysqli_stmt_get_result($stmt); - - if ($row = mysqli_fetch_assoc($result)) { - return $row; - } else { - $result = false; - return $result; - } - - mysqli_stmt_close($stmt); -} +include_once './includes/functions_user.php'; if ($_SERVER['REQUEST_METHOD'] == 'POST') { $errors = array(); @@ -64,7 +40,7 @@ if ($_SERVER['REQUEST_METHOD'] == 'POST') { $errors[] = "Your username must be 30 characters or less."; } - if (username_exists($dbc, $user_name) !== false) { + if (username_exists($user_name) !== false) { $errors[] = "The username '" . $user_name . "' has already been taken by another user."; } } @@ -91,19 +67,8 @@ if ($_SERVER['REQUEST_METHOD'] == 'POST') { } echo '</ul>'; } else { - $sql = "INSERT INTO users(user_name, user_pass, user_date) VALUES(?, ?, NOW());"; - $stmt = mysqli_stmt_init($dbc); - - if (!mysqli_stmt_prepare($stmt, $sql)) { - die('Could not create account due to internal error: ' . mysqli_error($dbc)); - } - $pass_hash = password_hash($user_pass, PASSWORD_DEFAULT); - - mysqli_stmt_bind_param($stmt, "ss", $user_name, $pass_hash); - mysqli_stmt_execute($stmt); - mysqli_stmt_close($stmt); - + register_user($user_name, $pass_hash); echo 'Account successfully registered! You can now <a href="signin.php">sign in</a>'; } } |