Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- include('connection.php');
- $errors = array();
- $succes = false;
- // REGISTER USER
- if (isset($_POST['reg_user'])) {
- $username = mysqli_real_escape_string($connection, $_POST['username']);
- $email = mysqli_real_escape_string($connection, $_POST['email']);
- $password = mysqli_real_escape_string($connection, $_POST['password']);
- $rol = mysqli_real_escape_string($connection, $_POST['rol']);
- // first check the database to make sure
- // a user does not already exist with the same username and/or email
- $user_check_query = "SELECT * FROM users WHERE username='$username' OR email='$email' LIMIT 1";
- $result = mysqli_query($connection, $user_check_query);
- $user = mysqli_fetch_assoc($result);
- if ($user) { // if user exists
- if ($user['username'] === $username) {
- array_push($errors,"Username existent!");
- }
- if ($user['email'] === $email) {
- array_push($errors,"Email existent!");
- }
- }
- // Finally, register user if there are no errors in the form
- if (count($errors) == 0) {
- $password = md5($password);//encrypt the password before saving in the database
- $query = "INSERT INTO users (username, password, email, role)
- VALUES('$username', '$password', '$email', '$rol')";
- mysqli_query($connection, $query);
- $succes = true;
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement