Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- require('testdb.php');
- session_start();
- if (isset($_POST['registersubm'])) {
- $fName = !empty($_POST['fName']) ? trim($_POST['fName']) : null;
- $username = !empty($_POST['username']) ? trim($_POST['username']) : null;
- $pass = !empty($_POST['password']) ? trim($_POST['password']) : null;
- $passcon = !empty($_POST['passwordcon']) ? trim($_POST['passwordcon']) : null;
- $email = !empty($_POST['email']) ? trim($_POST['email']) : null;
- // $avatar = $_POST['avatar'];
- $sql = "SELECT COUNT(username) AS num FROM registered_users WHERE username = :username";
- $stmt = $pdo->prepare($sql);
- $stmt->bindValue(':username', $username);
- $stmt->execute();
- $row = $stmt->fetch(PDO::FETCH_ASSOC);
- if($row['num'] > 0){
- //die('That username already exists!');
- $message = "Username already taken, Please choose another one";
- echo "<script type='text/javascript'>alert('$message');</script>";
- }
- else {
- $sql = "SELECT COUNT(email) AS num FROM registered_users WHERE email = :email";
- $stmt = $pdo->prepare($sql);
- $stmt->bindValue(':email', $email);
- $stmt->execute();
- $row = $stmt->fetch(PDO::FETCH_ASSOC);
- if($row['num'] > 0){
- $message = "That email is already registered to an account. Please use another one";
- echo "<script type='text/javascript'>alert('$message');</script>";
- }
- else {
- if ($_POST['password']!= $_POST['passwordcon']) {
- $message = "The passwords do not match";
- echo "<script type='text/javascript'>alert('$message');</script>";
- }
- else {
- $passwordHash = password_hash($pass, PASSWORD_BCRYPT, array("cost" => 12));
- $sql = "INSERT INTO registered_users (`fName`, `username`, `password`, `email`) VALUES (:fName, :username, :password, :email)";
- $stmt = $pdo->prepare($sql);
- $stmt->bindValue(':fName', $fName);
- $stmt->bindValue(':username', $username);
- $stmt->bindValue(':password', $passwordHash);
- $stmt->bindValue(':email', $email);
- // $stmt->bindValue(':avatar', $avatar);
- $result = $stmt->execute();
- $target_path = "user_avatars/" . $username;
- $target_path = $target_path.basename( $_FILES['avatar']['name']);
- if(move_uploaded_file($_FILES['avatar']['tmp_name'], $target_path)) {
- echo "File uploaded successfully!";
- } else{
- echo "Sorry, file not uploaded, please try again!";
- }
- //header("location: login.php?registered=true");
- }
- }
- }
- }
- ?>
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="utf-8">
- <title>Registration</title>
- <link rel="stylesheet" href="css/style.css" />
- </head>
- <body>
- <div class="form">
- <h1>User Registration Form</h1>
- <form name="registration" action="" method="post" enctype="multipart/form-data">
- <div class="formdes">
- <label for="fName"><b>Full name:</b></label>
- <input type="text" name="fName" placeholder="Enter Full name here" autocomplete="off" required
- Value = "<?php if (isset($fName)) {echo $fName;}?>" />
- </div>
- <div class="formdes">
- <label for="username"><b>Username:</b></label>
- <input type="text" name="username" placeholder="Enter Username here" autocomplete="off" required
- Value = "<?php if (isset($username)) {echo $username;}?>" />
- </div>
- <div class="formdes">
- <label for="email"><b>Email:</b></label>
- <input type="email" name="email" placeholder="Enter Email here" autocomplete="off" required
- Value = "<?php if (isset($email)) {echo $email;}?>"/>
- </div>
- <div class="formdes">
- <label for="password"><b>Password:</b></label>
- <input type="password" name="password" placeholder="Enter Password here" required />
- </div>
- <div class="formdes">
- <label for="passwordcon"><b>Confirm password:</b></label>
- <input type="password" name="passwordcon" placeholder="Repeat Password" required />
- </div>
- <div class="formdes">
- <label for="avatar"><b>Choose Avatar:</b></label>
- /<input type="file" name="avatar" accept="image/*" required />
- </div>
- <input type="submit" name="registersubm" value="Register" class="btnregistersubm" />
- </form>
- </div>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement