Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if (isset($_POST['registerBtn'])){
- $username = preg_replace("/[^A-Za-z0-9-]/","", $_POST['username']);
- $password = $_POST['password'];
- $rpassword = $_POST['rpassword'];
- $email = $_POST['email'];
- $errors = array();
- $checkUsername0 = $odb -> prepare("SELECT * FROM `users` WHERE `username`='".$username."'");
- $checkUsername0 -> execute();
- $countUsername0 = $checkUsername0 -> rowCount();
- if ($countUsername0 != 0)
- {
- $errors[] = 'Username is already taken';
- }
- if (empty($username) || empty($password) || empty($rpassword) || empty($email))
- {
- $errors[] = 'Please fill in all fields';
- }
- if ($password != $rpassword)
- {
- $errors[] = 'Passwords do not match';
- }
- if (empty($errors))
- {
- $insertUser = $odb -> prepare("INSERT INTO `users` VALUES(NULL, :username, :password, :email, 0, 0, 0, 0, '', 0)");
- $insertUser -> execute(array(':username' => $username, ':password' => SHA1($password), ':email' => $email));
- echo '<div class="message" id="message"><p><strong>SUCCESS: </strong>User has been registered. Redirecting....</p></div><meta http-equiv="refresh" content="3;url=login.php">';
- }
- else
- {
- echo '<div class="error" id="message"><p><strong>ERROR:</strong><br />';
- foreach($errors as $error)
- {
- echo '-'.$error.'<br />';
- }
- echo '</div>';
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement