Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- define('HOST','localhost');
- define('DB_NAME','kevinsmi_registration');
- define('USER','root');
- define('PASS','Sp1');
- try{
- $db = new PDO("mysql:host=" . HOST . ";dbname=" . DB_NAME, USER, PASS);
- global $db;
- }catch(PDOException $e){
- echo "An error occured while connecting to MySQL.";
- }
- $db_server = 'localhost';
- $db_username = 'root';
- $db_password = 'Sp1';
- $db_name = 'kevinsmi_registration';
- $sql = new mysqli($db_server, $db_username, $db_password, $db_name);
- if(
- isset($_POST['form_register'])
- ){
- $username = stripslashes($sql->real_escape_string(strip_tags($_POST['username'])));
- $name = stripslashes($sql->real_escape_string(strip_tags($_POST['name'])));
- $lastname = stripslashes($sql->real_escape_string(strip_tags($_POST['lastname'])));
- $email = stripslashes($sql->real_escape_string(strip_tags($_POST['email'])));
- $pass = $_POST['pass'];
- $rpass = $_POST['rpass'];
- // Verify if the user entered all the required informations
- if(
- !empty($name)
- && !empty($lastname)
- && !empty($email)
- && !empty($pass)
- && !empty($rpass)
- && $pass == $rpass
- && preg_match('/^[a-zA-Z0-9_\\-]{4,24}$/', $username)
- ){
- // Check if the email is already taken
- $cEmail = $db->prepare("SELECT * FROM users WHERE email = '$email'");
- $cEmail->execute();
- $checkEmail = $cEmail->fetch();
- // Check if the username is already taken
- $cUser = $db->prepare("SELECT * FROM users WHERE username = '$username'");
- $cUser->execute();
- $checkUser = $cUser->fetch();
- // If they are not taken
- if(
- $checkEmail !== true
- && $checkUser !== true
- ){
- // Password encryption
- $options = ['cost' => 12];
- $password = password_hash($pass, PASSWORD_BCRYPT, $options);
- $reg = $db->prepare("INSERT INTO users (username, name, lastname, email, password, role) VALUES (:username, :name, :lastname, :email, :password, :role)");
- $reg->execute([
- 'username' => $username,
- 'name' => $name,
- 'lastname' => $lastname,
- 'email' => $email,
- 'password' => $password,
- 'uuid' => $uuid,
- 'role' => 'user',
- ]);
- header('location:?1');
- }else{
- header('location:?2');
- }
- }else{
- header('location:?3');
- }
- }
- ?>
- <!DOCTYPE html>
- <html>
- <head>
- <title>Book Now - Client Sign Up</title>
- <link rel="stylesheet" type="text/css" href="style.css">
- <script src="http://cdn.lambocreeper.uk/bootstrap.js"></script>
- <link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.0.2/css/bootstrap.min.css">
- </head>
- <body>
- <form method="post">
- <input type="text" name="username" placeholder="Username"><br>
- <input type="text" name="name" placeholder="First Name"><br>
- <input type="text" name="lastname" placeholder="Last Name"><br>
- <input type="email" name="email" placeholder="Email address"><br>
- <input type="password" name="pass" placeholder="Password"><br>
- <input type="password" name="rpass" placeholder="Re-password"><br>
- <input type="submit" name="form_register" placeholder="Complete registration"><br>
- </form>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement