<?php

if (isset($_POST["submit"])) {

    $name = $_POST["name"];
    $email = $_POST["email"];
    $username = $_POST["uid"];
    $pwd = $_POST["pwd"];
    $pwdrepeat = $_POST["pwdrepeat"]; //naming db table variables to a post method / datubāžu lauku mainīgo nosaukšana

    require_once 'dbh.inc.php';
    require_once 'functions.inc.php';

    if (emptyInputSignup($name, $email, $username, $pwd, $pwdrepeat) !== false) { // calling functions from functions.inc.php / funkciju izsaukšana functions.inc.php
        header("location: ../signup.php?error=emptyInput"); //relates to singup.php error messages / piesaistāms singup.php erora ziņām
        exit(); //methot that stops the script / metode kura apstādina skriptu
    }
    if (invalidUid($username) !== false) {
        header("location: ../signup.php?error=invalidUsername");
        exit();
    }
    if (invalidEmail($email) !== false) {
        header("location: ../signup.php?error=invalidEmail");
        exit();
    }
    if (pwdMatch($pwd, $pwdrepeat) !== false) {
        header("location: ../signup.php?error=passwordsDontMatch");
        exit();
    }
    if (uidExists($conn, $username, $email) !== false) {
        header("location: ../signup.php?error=usernameTaken");
        exit();
    }

    createUser($conn, $name, $email, $username, $pwd,);
} else {
    header("location: ../signup.php");
    exit(); 
}
?>
