Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- require "header.php";
- ?>
- <?php
- include "class.php";
- $user = new User;
- $user->signup();
- ?>
- <main>
- <section class="banner">
- <h1 class="title">Sign Up</h1>
- <div class="wrapper-main">
- <section class= "section-default">
- <form action="" class="signup" method="post">
- <input type="text" name="uid" placeholder="Username">
- <input type="text" name="mail" placeholder="Email">
- <input type="Password" name="pwd" placeholder="Password">
- <input type="Password" name="pwd-repeat" placeholder="Repeat Password">
- <button type="submit" name="signup-submit">Sign up</button>
- </form>
- </section>
- </div>
- </section>
- </main>
- ----------------------------------------------------------------------------------------------------------------------
- <?php
- class Db{
- private $servername;
- private $username;
- private $password;
- private $dBName;
- public function connect(){
- $this->servername = "localhost";
- $this->username = "root";
- $this->password = "";
- $this->dBName = "bank";
- $conn = new mysqli($this->servername, $this->username, $this->password, $this->dBName);
- return $conn;
- echo "haha";
- }
- }
- class User extends Db{
- public $username;
- public $email;
- public $password;
- public $passwordRepeat;
- $db= new Db;
- $db->connect();
- public function signup(){
- if (isset($_POST['signup-submit'])){
- $username = $_POST ['uid'];
- $email= $_POST ['mail'];
- $password = $_POST ['pwd'];
- $passwordRepeat= $_POST ['pwd-repeat'];
- if (empty($username)|| empty($email) || empty($password) || empty($passwordRepeat) ){
- echo '<p class= "signuperror"> Fill in all fields!</p>';
- }
- elseif(!filter_var($email,FILTER_VALIDATE_EMAIL) && !preg_match("/^[a-zA-Z0-9*$/", $username)) {
- echo '<p class= "signuperror"> Invalid username and email!</p>';
- }
- elseif (!filter_var($email,FILTER_VALIDATE_EMAIL)) {
- echo '<p class= "signuperror"> Invalid username!</p>';
- }
- elseif (!preg_match("/^[a-zA-Z0-9]*$/", $username)){
- echo '<p class= "signuperror"> Invalid email!</p>';
- exit();
- }
- elseif ($password !== $passwordRepeat)
- {
- echo '<p class= "signuperror"> Password do not match!</p>';
- }
- else{
- $sql = "SELECT uidUser FROM users WHERE uidUser=?";
- $stmt = mysqli_stmt_init($conn);
- if(!mysqli_stmt_prepare($stmt,$sql))
- {
- echo '<p class= "signuperror"> SQL ERROR!</p>';
- }
- else{
- mysqli_stmt_bind_param($stmt,"s",$username);
- mysqli_stmt_execute($stmt);
- mysqli_stmt_store_result($stmt);
- $resultcheck = mysqli_stmt_num_rows($stmt);
- if ($resultcheck>0) {
- echo '<p class= "signuperror"> Username taken!</p>';
- }
- else{
- $sql = "INSERT INTO users (uidUser, emailUser, pwdUser) VALUES (?,?,?)";
- $stmt = mysqli_stmt_init($conn);
- if(!mysqli_stmt_prepare($stmt,$sql)){
- header("Location: ../signup.php?error=sqlerror");
- exit();
- }
- else
- {
- $hashedPwd = password_hash($password, PASSWORD_DEFAULT);
- mysqli_stmt_bind_param($stmt, "sss", $username, $email, $hashedPwd);
- mysqli_stmt_execute($stmt);
- echo '<p class= "signupsuccess"> Signup successful </p>';
- }
- }
- }
- mysqli_stmt_close($stmt);
- mysqli_close($conn);
- }
- }/*end if*/
- else
- {
- header("Location: ../signup.php");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement