Guest User

Untitled

a guest
Jun 23rd, 2018
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.44 KB | None | 0 0
  1. <?php
  2. class Register
  3. {
  4. private $_db;
  5. public function __construct()
  6. {
  7. $this->_db = new Connection();
  8. $this->_db = $this->_db->dbConnect();
  9. }
  10. public function CheckUname($username,$email,$password,$groups,$level)
  11. {
  12. if(!empty($username)&&!empty($email)&&!empty($password)&&!empty($groups)&&!empty($level))
  13. {
  14. $chk1 = $this->_db->prepare("SELECT user_name FROM admins WHERE user_name = ?");
  15. $chk1->bindParam(1,$username);
  16. $chk1->execute();
  17. if($chk1->rowCount() == 1)
  18. {
  19. $notice['username_exists'] = "Try different username";
  20. }else{
  21. $chk2 = $this->_db->prepare("SELECT email_address FROM admins WHERE email_address = ?");
  22. $chk2->bindParam(1,$email);
  23. $chk2->execute();
  24. if($chk2->rowCount() == 1)
  25. {
  26. $notice['email_exists'] = "The email address that you have entered is already exists in database";
  27. }else{
  28. $this->NewAdmin($username,$email,$password,$groups,$level);
  29. $notice['success_message'] = "New admin was successfully added";
  30. }
  31. }
  32. }
  33. }
  34. public function NewAdmin($username,$email,$password,$groups,$level)
  35. {
  36. if(!empty($username)&&!empty($email)&&!empty($password)&&!empty($groups)&&!empty($level))
  37. {
  38. $reg = $this->_db->prepare("INSERT INTO admins (user_name, email_address, password_hash, group_admin, date_joined, admin_level) VALUES ( ?, ?, ?, ?, NOW(), ?)");
  39. $reg->bindParam(1,$username);
  40. $reg->bindParam(2,$email);
  41. $reg->bindParam(3,$password);
  42. $reg->bindParam(4,$groups);
  43. $reg->bindParam(5,$level);
  44. $reg->execute();
  45. }
  46. }
  47. }
  48. ?>
  49.  
  50. <?php
  51. if(isset($notice['email_validation'])){
  52. echo "
  53. <div class='alert alert-danger'>
  54. <strong>Hey!</strong> ".$notice['email_validation'].".
  55. </div>
  56. ";
  57. }
  58. if(isset($notice['username_exists'])){
  59. echo "
  60. <div class='alert alert-danger'>
  61. <strong>Hey!</strong> ".$notice['username_exists'].".
  62. </div>
  63. ";
  64. }
  65. if(isset($notice['email_exists'])) {
  66. echo "
  67. <div class='alert alert-danger'>
  68. <strong>Hey!</strong> ".$notice['email_exists'].".
  69. </div>
  70. ";
  71. }
  72. if(isset($notice['success_message'])) {
  73. echo "
  74. <div class='alert alert-success'>
  75. <strong>Hey!</strong> ".$notice['success_message'].".
  76. </div>
  77. ";
  78. }
  79. ?>
Add Comment
Please, Sign In to add comment