<commit_before><?php

require_once 'functions.php';

// Check if user made post request, otherwise send back to landing page
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
  header('Location: ../../');
  die();
}

// Check if all registration fields are entered, else return to landing page and display error message
if (!isset($_POST['fullName']) || !isset($_POST['email']) || !isset($_POST['password']) || !isset($_POST['password_reenter'])) {
  $_SESSION['registerError'] = 'Please fill in all fields.';
  header('Location: ../../');
  die();
}

// Assign variables
$fullName = $_POST['fullName'];
$email = $_POST['email'];
$password = $_POST['password'];
$passwordReenter = $_POST['password_reenter'];

// Validate and escape all fields
$fullNameSanitized = validateString($fullName);
$emailSanitized = validateEmail($email);
$passwordSanitized = validateString($password);
$passwordReenterSanitized = validateString($passwordReenter);

// Check if email already exists in database
if ($dbConnection->query("SELECT email FROM users WHERE email = '$emailSanitized' LIMIT 1")->fetch()) {
  $_SESSION['registerError'] = 'Email is already registered. Please try another email adress.';
  header('Location: ../../');
  die();
}

// Check if both password fields match
if ($passwordSanitized !== $passwordReenterSanitized) {
  $_SESSION['registerError'] = 'Password fields do not match. Please try again.';
  die(var_dump($_SESSION));
  header('Location: ../../');
  die();
}<commit_msg>Removed debugging code<commit_after><?php

require_once 'functions.php';

// Check if user made post request, otherwise send back to landing page
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
  header('Location: ../../');
  die();
}

// Check if all registration fields are entered, else return to landing page and display error message
if (!isset($_POST['fullName']) || !isset($_POST['email']) || !isset($_POST['password']) || !isset($_POST['password_reenter'])) {
  $_SESSION['registerError'] = 'Please fill in all fields.';
  header('Location: ../../');
  die();
}

// Assign variables
$fullName = $_POST['fullName'];
$email = $_POST['email'];
$password = $_POST['password'];
$passwordReenter = $_POST['password_reenter'];

// Validate and escape all fields
$fullNameSanitized = validateString($fullName);
$emailSanitized = validateEmail($email);
$passwordSanitized = validateString($password);
$passwordReenterSanitized = validateString($passwordReenter);

// Check if email already exists in database
if ($dbConnection->query("SELECT email FROM users WHERE email = '$emailSanitized' LIMIT 1")->fetch()) {
  $_SESSION['registerError'] = 'Email is already registered. Please try another email adress.';
  header('Location: ../../');
  die();
}

// Check if both password fields match
if ($passwordSanitized !== $passwordReenterSanitized) {
  $_SESSION['registerError'] = 'Password fields do not match. Please try again.';
  header('Location: ../../');
  die();
}
{'fraction_non_alphanumeric': 0.17509331523583305, 'fraction_numerical': 0.0006786562606040041, 'mean_word_length': 5.380952380952381, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3485592', 'n_tokens_mistral': 825, 'n_tokens_neox': 818, 'n_words': 245}