Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- if (isset($_POST['signup-submit'])) {
- require 'db.php';
- $username = $_POST['uid'];
- $email = $_POST['mail'];
- $password = $_POST['pwd'];
- $passwordRepeat = $_POST['pwd-repeat'];
- if (empty($username) || empty($email) || empty($password) || empty($passwordRepeat)) {
- header("Location: ../index.html?error=emptyfields&uid=".$username."&mail=".$email);
- exit();
- }
- else if (!filter_var($email, FILTER_VALIDDATA_EMAIL) && !preg_match("/[a-zA-Z0-9]*$/", $username)) {
- header("Location: ../index.html?error=invalidmailuid");
- exit();
- }
- else if (!filter_var($email, FILTER_VALIDDATA_EMAIL)) {
- header("Location: ../index.html?error=invalidmail&uid=".$username);
- exit();
- }
- else if (!preg_match("/[a-zA-Z0-9]*$/", $username)) {
- header("Location: ../index.html?error=invaliduid&mail=".$email);
- exit();
- }
- else if ($password !== $passwordRepeat) {
- header("Location: ../index.html?error=passwordcheck&uid=".$username."&mail=".$email);
- exit();
- }
- else {
- $sql = "SELECT * FROM users WHERE uidUsers=?;";
- $stmt = mysqli_stmt_init($conn);
- if (!mysqli_stmt_prepare($stmt, $sql)) {
- header("Location: ../index.html?error=sqlerror");
- exit();
- }
- else {
- mysqli_stmt_bind_param($stmt, "s", $mailuid);
- mysqli_stmt_execute($stmt);
- mysqli_stmt_store_result($stmt);
- $resultCheck = mysqli_stmt_num_rows($stmt);
- if ($resultCheck > 0) {
- header("Location: ../index.html?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: ../index.html?error=sqlerror");
- }
- else {
- $hashedPwd = password_hash($password, PASSWORD_DEFAULT);
- mysqli_stmt_bind_param($stmt, "sss", $username, $email, $hashedPwd);
- mysqli_stmt_execute($stmt);
- header("Location: ../index.html?signup=success");
- exit();
- }
- }
- }
- }
- mysqli_stmt_close($stmt);
- mysqli_close($conn);
- }
- else {
- header("Location: ../index.html");
- exit();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement