Advertisement
aungpyaythar123

signup.php

May 29th, 2017
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.52 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3.   <head>
  4.     <title>Mismatch - Sign Up</title>
  5.     <meta charset="utf-8">
  6.   </head>
  7.   <body>
  8. <?php
  9.   require_once('appvars.php');
  10.   require_once('connectvars.php');
  11.  
  12.   // Connect to the database
  13.   $dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
  14.  
  15.   if(isset($_POST['submit'])
  16.   {
  17.     // Grab the profile data from POST
  18.     $username = $_POST['username']);
  19.     $password1 = $_POST['password1']);
  20.     $password2 = $_POST['password2']);
  21.  
  22.     if(!empty($username) && !empty($password1) && !empty($password2) &&
  23.     ($password1 == $password2) )
  24.     {
  25.       // Make sure someone isn't already registered with this username
  26.      
  27.       $query = "SELECT * FROM mismatch_user WHERE username = '$username'";
  28.      
  29.       $data = mysqli_query($dbc, $query);
  30.       if(mysqli_num_rows($data) == 0)
  31.       {
  32.         // The username is unique, so insert the data into the database
  33.         $query = "INSERT INTO mismatch_user (username, password, date) VALUES" .
  34.                  "('$username', SHA('$password1'), NOW())";
  35.         mysqli_query($dbc, $query);
  36.        
  37.         // Confirm success with the user
  38.         echo '<p>Your new account has been successfully created. You\'re ready to log in and ' .
  39.              '<a href="editprofile.php">edit your profile</a>.</p>';
  40.         mysqli_close($dbc);
  41.         exit();
  42.       }
  43.       else
  44.       {
  45.          // An account already exists for this username, so display an error message
  46.          echo '<p class="error">An account already exists for this username. ' .
  47.               'Please use a different address.</p>';
  48.          $username = "";
  49.       }
  50.     }
  51.     else
  52.     {
  53.        echo '<p class="error">You must enter all of the sign-up data, ' .
  54.              'including the desired password twice.</p>';
  55.     }
  56.   }
  57. ?>
  58.  
  59.     <p>Please enter you username and desired password to sign up to Mismatch.</p>
  60.     <form method="post" action="<?php echo $_SERVER['PHP_SELF']?>">
  61.       <fieldset>
  62.         <legend>Registration Info</legend>
  63.         <label for="username">Username:</label>
  64.         <input type="text" id="username" name="username" value="<?php if(!empty($username)) echo $username;?>"><br>  
  65.         <label for="password1">Password:</label>
  66.         <input type="password" id="password1" name="password1" value="<?php if(!empty($password1)) echo $password1;?>"><br>
  67.         <label for="password2">Password (retype):</label>
  68.         <input type="password" id="password2" name="password2"><br>
  69.       </fieldset>
  70.     </form>
  71.   </body>
  72. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement