Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $servername = "localhost":
- $dBUsername = "";
- $dBPassword = "";
- $dBName = "admhap_Users";
- $conn = mysqli_connect($servername, $dBUsername, $dBPassword, $dBName);
- if(!$conn) {
- die("Connection failed: ".mysqli_connect_error());
- }
- <?php
- require "header.php";
- ?>
- <main>
- <div>
- <section>
- <h1>Aanmelden</h1>
- <form action="back-end/signup.be.php" method="post">
- <input type="text" name="uid" placeholder="Gebruikersnaam...">
- <input type="text" name="mail" placeholder="E-mail...">
- <input type="password" name="ww" placeholder="Wachtwoord...">
- <input type="password" name="ww-her" placeholder="Herhaal wachtwoord...">
- <button type="submit" name="signup-submit">Aanmelden</button>
- </form>
- </section>
- </div>
- </main>
- <?php
- require "footer.php";
- ?>
- <?php
- if (isset($_POST['signup-submit'])) {
- require 'dbh.be.php';
- $username = $_POST['uid'];
- $email = $_POST['mail'];
- $password = $_POST['ww'];
- $passwordRepeat = $_POST['ww-her'];
- if (empty($username) || empty($email) || empty($password) || empty($passwordRepeat)) {
- header("Location: ../signup.php?error=emptyfields&uid=".$username."&mail=".$email);
- exit();
- }
- else if (!filter_var($email, FILTER_VALIDATE_EMAIL) && !preg_match("/^[a-zA-Z0-9]*$/", $username)) {
- header("Location: ../signup.php?error=invalidmailuid");
- exit();
- }
- else if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
- header("Location: ../signup.php?error=invalidmail&uid=".$username);
- exit();
- }
- else if (!preg_match("/^[a-zA-Z0-9]*$/", $username)) {
- header("Location: ../signup.php?error=invaliduid&mail=".$email);
- exit();
- }
- else if ($password !== $passwordRepeat) {
- header("Location: ../signup.php?error=passwordcheck&uid=".$username."&mail=".$email);
- exit();
- }
- else {
- $sql = "SELECT gebruikersnaam FROM gebruikers WHERE gebruikersnaam=?";
- $stmt = mysqli_stmt_init($conn);
- if (!mysqli_stmt_prepare($stmt, $sql)) {
- header("Location: ../signup.php?error=sqlerror");
- exit();
- }
- else {
- mysqli_stmt_bind_param($stmt, "s", $username);
- mysqli_stmt_execute($stmt);
- mysqli_stmt_store_result($stmt);
- $resultCheck = mysqli_stmt_num_rows($stmt);
- if ($resultCheck > 0) {
- header("Location: ../signup.php?error=usertaken&mail=".$email);
- exit();
- }
- else {
- $sql = "INSERT INTO users (uidUsers, emailUsers, pwdUsers) VALUES (?, ?, ?)";
- $stmt = mysqli_stmt_init($conn);
- if (!mysqli_stmt_prepare($stmt, $sql)) {
- header("Location: ../signup.php?error=sqlerror");
- exit();
- }
- else{
- $hashedPwd = password_hash($password, PASSWORD_DEFAULT);
- mysqli_stmt_bind_param($stmt, "sss", $username, $email, $hashedPwd);
- mysqli_stmt_execute($stmt);
- header("Location: ../signup.php?signup=succes");
- exit();
- }
- }
- }
- }
- mysqli_stmt_close($stmt);
- mysqli_close($conn);
- }
- else{
- header("Location: ../signup.php?");
- exit();
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement