Advertisement
Guest User

Singup

a guest
May 29th, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.38 KB | None | 0 0
  1. <?php
  2. include('connection.php');
  3. $errors = array();
  4. $succes = false;
  5. // REGISTER USER
  6. if (isset($_POST['reg_user'])) {
  7.     $username = mysqli_real_escape_string($connection, $_POST['username']);
  8.     $email = mysqli_real_escape_string($connection, $_POST['email']);
  9.     $password = mysqli_real_escape_string($connection, $_POST['password']);
  10.     $rol = mysqli_real_escape_string($connection, $_POST['rol']);
  11.  
  12.  
  13.     // first check the database to make sure
  14.     // a user does not already exist with the same username and/or email
  15.     $user_check_query = "SELECT * FROM users WHERE username='$username' OR email='$email' LIMIT 1";
  16.     $result = mysqli_query($connection, $user_check_query);
  17.     $user = mysqli_fetch_assoc($result);
  18.  
  19.     if ($user) { // if user exists
  20.         if ($user['username'] === $username) {
  21.             array_push($errors,"Username existent!");
  22.         }
  23.  
  24.         if ($user['email'] === $email) {
  25.             array_push($errors,"Email existent!");
  26.         }
  27.     }
  28.  
  29.     // Finally, register user if there are no errors in the form
  30.     if (count($errors) == 0) {
  31.         $password = md5($password);//encrypt the password before saving in the database
  32.         $query = "INSERT INTO users (username, password, email, role)
  33.               VALUES('$username', '$password', '$email', '$rol')";
  34.         mysqli_query($connection, $query);
  35.         $succes = true;
  36.     }
  37. }
  38. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement