Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- if (isset($_POST['submit'])){
- $dbServername = "localhost";
- $dbUsername = "root";
- $dbPassword = "";
- $dbName = "loginsystem";
- $conn = mysqli_connect($dbServername, $dbUsername, $dbPassword, $dbName);
- /* check connection */
- if (mysqli_connect_errno()) {
- printf("Connect failed: %s\n", mysqli_connect_error());
- exit();
- }
- $first = mysqli_real_escape_string($conn, $_POST['first']);
- $last = mysqli_real_escape_string($conn, $_POST['last']);
- $email = mysqli_real_escape_string($conn, $_POST['email']);
- $uid = mysqli_real_escape_string($conn, $_POST['uid']);
- $pwd = mysqli_real_escape_string($conn, $_POST['pwd']);
- //error handlers
- //check for empty fields
- if (empty($first) || empty($last) || empty($email) || empty($uid) || empty($pwd)){
- header("Location: ../signup.php?signup=empty");
- exit();
- } else {
- //Check if input character are valid
- if(!preg_match("/^[a-zA-Z]*$/", $first ) || !preg_match("/^[a-zA-Z]*$/", $last )) {
- header("Location: ../signup.php?signup=invalid");
- exit();
- }else {
- //Check if email is valid
- if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
- header("Location: ../signup.php?signup=email");
- exit();
- } else {
- $sql = "SELECT * FROM users WHERE user_uid= '$uid'" ;
- $result = mysqli_query($conn, $sql);
- $resultCheck = mysqli_num_rows($result);
- if ($resultCheck > 0) {
- header("Location: ../signup.php?signup=usertaken");
- exit(); {
- }
- } else {
- //Hashing the password
- $hashedPwd = password_hash($pwd, PASSWORD_DEFAULT);
- $sql = "INSERT INTO users (user_first, user_last, user_email, user_uid, user_pwd) VALUES ($first, $last, $email, $uid, $pwd);";
- mysqli_query($conn, $sql);
- } header("Location: ../signup.php?signup=succes");
- exit();
- }
- }
- }
- }else{
- header("Location: ../signup.php");
- exit();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement