Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /* form.php */
- session_start();
- $_SESSION['message'] = '';
- $mysqli = new mysqli("localhost", "root", "root", "accounts");
- // Create errors object
- $errors = new stdClass();
- // Error if passwords don't match
- if( $password != $confirm_password ){
- $errors->password = 'Your passwords must match';
- }
- if ($_SERVER["REQUEST_METHOD"] == "POST") {
- //password check
- if ($_POST['password'] == $_POST['confirmpassword']) {
- $username = $mysqli->real_escape_string($_POST['username']);
- $email = $mysqli->real_escape_string($_POST['email']);
- $password = hash( 'sha256', $_POST['password'] );
- $bday = $mysqli->real_escape_string($_POST['bday']);
- }
- //set session variables to display on welcome page
- $_SESSION['username'] = $username;
- $_SESSION['bday'] = $bday;
- //create SQL query string for inserting data into the database
- $sql = "INSERT INTO users (username, email, password, bday) "
- . "VALUES ('$username', '$email', '$password', '$bday')";
- // Sanitise input
- $password = filter_var( $_POST['password'] , FILTER_SANITIZE_STRING );
- $confirm_password = filter_var( $_POST['confirm_password'], FILTER_SANITIZE_STRING );
- if ($mysqli->query($sql) === true) {
- $_SESSION[ 'message' ] = "Registration succesful! Added $username to the database!";
- //redirect the user to welcome.php
- header( "location: welcome.php" );
- }
- }
- ?>
- <link href="//db.onlinewebfonts.com/c/a4e256ed67403c6ad5d43937ed48a77b?family=Core+Sans+N+W01+35+Light" rel="stylesheet" type="text/css"/>
- <link rel="stylesheet" href="form.css" type="text/css">
- <div class="body-content">
- <div class="module">
- <h1>Create an account</h1>
- <form class="form" action="form.php" method="post" enctype="multipart/form-data" autocomplete="off">
- <div class="alert alert-error"><?= $_SESSION['message'] ?></div>
- Name
- <input type="text" placeholder="User Name" name="username" required />
- Email
- <input type="email" placeholder="Email" name="email" required />
- Password
- <input type="password" placeholder="Password" name="password" autocomplete="new-password" required />
- Confirm Password
- <input type="password" placeholder="Confirm Password" name="confirmpassword" autocomplete="new-password" required />
- Date Of Birth
- <input type="date" placeholder="Birth Date dd/mm/yy" name="bday" required />
- <input type="submit" value="Register" name="register" class="btn btn-block btn-primary" />
- </form>
- </div>
- </div>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement