Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class Register
- {
- private $_db;
- public function __construct()
- {
- $this->_db = new Connection();
- $this->_db = $this->_db->dbConnect();
- }
- public function CheckUname($username,$email,$password,$groups,$level)
- {
- if(!empty($username)&&!empty($email)&&!empty($password)&&!empty($groups)&&!empty($level))
- {
- $chk1 = $this->_db->prepare("SELECT user_name FROM admins WHERE user_name = ?");
- $chk1->bindParam(1,$username);
- $chk1->execute();
- if($chk1->rowCount() == 1)
- {
- $notice['username_exists'] = "Try different username";
- }else{
- $chk2 = $this->_db->prepare("SELECT email_address FROM admins WHERE email_address = ?");
- $chk2->bindParam(1,$email);
- $chk2->execute();
- if($chk2->rowCount() == 1)
- {
- $notice['email_exists'] = "The email address that you have entered is already exists in database";
- }else{
- $this->NewAdmin($username,$email,$password,$groups,$level);
- $notice['success_message'] = "New admin was successfully added";
- }
- }
- }
- }
- public function NewAdmin($username,$email,$password,$groups,$level)
- {
- if(!empty($username)&&!empty($email)&&!empty($password)&&!empty($groups)&&!empty($level))
- {
- $reg = $this->_db->prepare("INSERT INTO admins (user_name, email_address, password_hash, group_admin, date_joined, admin_level) VALUES ( ?, ?, ?, ?, NOW(), ?)");
- $reg->bindParam(1,$username);
- $reg->bindParam(2,$email);
- $reg->bindParam(3,$password);
- $reg->bindParam(4,$groups);
- $reg->bindParam(5,$level);
- $reg->execute();
- }
- }
- }
- ?>
- <?php
- if(isset($notice['email_validation'])){
- echo "
- <div class='alert alert-danger'>
- <strong>Hey!</strong> ".$notice['email_validation'].".
- </div>
- ";
- }
- if(isset($notice['username_exists'])){
- echo "
- <div class='alert alert-danger'>
- <strong>Hey!</strong> ".$notice['username_exists'].".
- </div>
- ";
- }
- if(isset($notice['email_exists'])) {
- echo "
- <div class='alert alert-danger'>
- <strong>Hey!</strong> ".$notice['email_exists'].".
- </div>
- ";
- }
- if(isset($notice['success_message'])) {
- echo "
- <div class='alert alert-success'>
- <strong>Hey!</strong> ".$notice['success_message'].".
- </div>
- ";
- }
- ?>
Add Comment
Please, Sign In to add comment