Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // Check whether a user with the given username exist or not
- $query = "SELECT 1 FROM public.user WHERE username = :username";
- $query_params = array(':username' => $username);
- try{
- $stmt = $pdo->prepare($query);
- $result = $stmt->execute($query_params);
- }
- catch(PDOException $ex){
- echo '<span style="color: red">ERROR! Code: 009</span>';
- exit;
- }
- $row = $stmt->fetch();
- // When a user exist with the username, registration fails
- if($row){
- $error = 1;
- }
- // If no error has occurred so far, create the user
- if($error != 1) {
- // If the register as administrator checkbox was activated in the registration form, create an administrator account, when not create a normal account
- if($_POST['isAdmin'] == 'on'){
- $query = "INSERT INTO public.user (username, unencrypted_password, is_admin) VALUES (:username, :unencrypted_password, TRUE)";
- }else{
- $query = "INSERT INTO public.user (username, unencrypted_password, is_admin) VALUES (:username, :unencrypted_password, FALSE)";
- }
- $query_params = array(':username' => $username, ':unencrypted_password' => $password);
- try{
- $stmt = $pdo->prepare($query);
- $result = $stmt->execute($query_params);
- }
- catch(PDOException $ex){
- echo '<span style="color: red">ERROR! Code: 010</span>';
- exit;
- }
- }
- ?>
Add Comment
Please, Sign In to add comment