Advertisement
Guest User

Untitled

a guest
Nov 24th, 2018
258
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.22 KB | None | 0 0
  1. <?php
  2. require "header.php";
  3. ?>
  4.  
  5. <?php
  6. include "class.php";
  7.  
  8. $user = new User;
  9. $user->signup();
  10.  
  11.  
  12.  
  13.  
  14. ?>
  15.  
  16.  
  17. <main>
  18. <section class="banner">
  19. <h1 class="title">Sign Up</h1>
  20. <div class="wrapper-main">
  21. <section class= "section-default">
  22. <form action="" class="signup" method="post">
  23. <input type="text" name="uid" placeholder="Username">
  24. <input type="text" name="mail" placeholder="Email">
  25. <input type="Password" name="pwd" placeholder="Password">
  26. <input type="Password" name="pwd-repeat" placeholder="Repeat Password">
  27. <button type="submit" name="signup-submit">Sign up</button>
  28. </form>
  29. </section>
  30. </div>
  31. </section>
  32. </main>
  33.  
  34.  
  35. ----------------------------------------------------------------------------------------------------------------------
  36.  
  37.  
  38.  
  39. <?php
  40.  
  41.  
  42. class Db{
  43.  
  44. private $servername;
  45. private $username;
  46. private $password;
  47. private $dBName;
  48.  
  49. public function connect(){
  50. $this->servername = "localhost";
  51. $this->username = "root";
  52. $this->password = "";
  53. $this->dBName = "bank";
  54.  
  55. $conn = new mysqli($this->servername, $this->username, $this->password, $this->dBName);
  56. return $conn;
  57. echo "haha";
  58. }
  59. }
  60.  
  61. class User extends Db{
  62. public $username;
  63. public $email;
  64. public $password;
  65. public $passwordRepeat;
  66.  
  67. $db= new Db;
  68. $db->connect();
  69.  
  70.  
  71. public function signup(){
  72.  
  73. if (isset($_POST['signup-submit'])){
  74.  
  75. $username = $_POST ['uid'];
  76. $email= $_POST ['mail'];
  77. $password = $_POST ['pwd'];
  78. $passwordRepeat= $_POST ['pwd-repeat'];
  79.  
  80. if (empty($username)|| empty($email) || empty($password) || empty($passwordRepeat) ){
  81. echo '<p class= "signuperror"> Fill in all fields!</p>';
  82. }
  83. elseif(!filter_var($email,FILTER_VALIDATE_EMAIL) && !preg_match("/^[a-zA-Z0-9*$/", $username)) {
  84. echo '<p class= "signuperror"> Invalid username and email!</p>';
  85. }
  86. elseif (!filter_var($email,FILTER_VALIDATE_EMAIL)) {
  87. echo '<p class= "signuperror"> Invalid username!</p>';
  88. }
  89. elseif (!preg_match("/^[a-zA-Z0-9]*$/", $username)){
  90. echo '<p class= "signuperror"> Invalid email!</p>';
  91. exit();
  92. }
  93. elseif ($password !== $passwordRepeat)
  94. {
  95. echo '<p class= "signuperror"> Password do not match!</p>';
  96. }
  97. else{
  98. $sql = "SELECT uidUser FROM users WHERE uidUser=?";
  99. $stmt = mysqli_stmt_init($conn);
  100. if(!mysqli_stmt_prepare($stmt,$sql))
  101. {
  102. echo '<p class= "signuperror"> SQL ERROR!</p>';
  103. }
  104. else{
  105. mysqli_stmt_bind_param($stmt,"s",$username);
  106. mysqli_stmt_execute($stmt);
  107. mysqli_stmt_store_result($stmt);
  108. $resultcheck = mysqli_stmt_num_rows($stmt);
  109. if ($resultcheck>0) {
  110.  
  111. echo '<p class= "signuperror"> Username taken!</p>';
  112. }
  113. else{
  114. $sql = "INSERT INTO users (uidUser, emailUser, pwdUser) VALUES (?,?,?)";
  115. $stmt = mysqli_stmt_init($conn);
  116. if(!mysqli_stmt_prepare($stmt,$sql)){
  117. header("Location: ../signup.php?error=sqlerror");
  118. exit();
  119. }
  120. else
  121. {
  122. $hashedPwd = password_hash($password, PASSWORD_DEFAULT);
  123.  
  124. mysqli_stmt_bind_param($stmt, "sss", $username, $email, $hashedPwd);
  125. mysqli_stmt_execute($stmt);
  126. echo '<p class= "signupsuccess"> Signup successful </p>';
  127. }
  128. }
  129. }
  130. mysqli_stmt_close($stmt);
  131. mysqli_close($conn);
  132.  
  133. }
  134. }/*end if*/
  135. else
  136. {
  137. header("Location: ../signup.php");
  138. }
  139. }
  140.  
  141.  
  142. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement