Advertisement
dfeher

Untitled

Mar 13th, 2019
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.10 KB | None | 0 0
  1. <?php
  2. /* form.php */
  3.     session_start();
  4.     $_SESSION['message'] = '';
  5.     $mysqli = new mysqli("localhost", "root", "root", "accounts");
  6.  
  7. if ($_SERVER["REQUEST_METHOD"] == "POST") {
  8.     //password check
  9.     if ($_POST['password'] == $_POST['confirmpassword']) {
  10.         $username = $mysqli->real_escape_string($_POST['username']);
  11.         $email = $mysqli->real_escape_string($_POST['email']);
  12.         $password = hash( 'sha256', $_POST['password'] );
  13.         $bday = $mysqli->real_escape_string($_POST['bday']);
  14.     }
  15. }
  16.  
  17.  
  18.     //set session variables to display on welcome page
  19.     $_SESSION['username'] = $username;
  20.     $_SESSION['bday'] = $bday;
  21.  
  22.     //create SQL query string for inserting data into the database
  23.     $sql = "INSERT INTO users (username, email, password, bday) "
  24.     . "VALUES ('$username', '$email', '$password', '$bday')";
  25.  
  26.     if ($mysqli->query($sql) === true) {
  27.     $_SESSION[ 'message' ] = "Registration succesful! Added $username to the database!";
  28.     //redirect the user to welcome.php
  29.     header( "location: welcome.php" );
  30. }
  31.  
  32. ?>
  33. <link href="//db.onlinewebfonts.com/c/a4e256ed67403c6ad5d43937ed48a77b?family=Core+Sans+N+W01+35+Light" rel="stylesheet" type="text/css"/>
  34. <link rel="stylesheet" href="form.css" type="text/css">
  35. <div class="body-content">
  36.   <div class="module">
  37.     <h1>Create an account</h1>
  38.     <form class="form" action="form.php" method="post" enctype="multipart/form-data" autocomplete="off">
  39.       <div class="alert alert-error"><?= $_SESSION['message'] ?></div>
  40.       <input type="text" placeholder="User Name" name="username" required />
  41.       <input type="email" placeholder="Email" name="email" required />
  42.       <input type="password" placeholder="Password" name="password" autocomplete="new-password" required />
  43.       <input type="password" placeholder="Confirm Password" name="confirmpassword" autocomplete="new-password" required />
  44.       <input type="date" placeholder="Birth Date dd/mm/yy" name="bday" required />
  45.       <input type="submit" value="Register" name="register" class="btn btn-block btn-primary" />
  46.     </form>
  47.   </div>
  48. </div>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement