Advertisement
Guest User

HCI-Task-2-Sign Up

a guest
Jan 23rd, 2019
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.38 KB | None | 0 0
  1. <?php require_once('connection.php'); ?>
  2. <?php
  3. function error($error) {
  4.     header('Location: sign_up.php?error=' . $error);
  5.     exit();
  6. }
  7.  
  8.  
  9. if (isset($_POST['submit'])) {
  10.     $username = $_POST['username'];
  11.     $firstName = $_POST['firstName'];
  12.     $secondName = $_POST['secondName'];
  13.     $email = $_POST['email'];
  14.  
  15.     if ($_POST['password1'] == $_POST['password2']) {
  16.        $password = password_hash($_POST['password1'], PASSWORD_DEFAULT);
  17.        if ( ctype_alnum($username)) {
  18.         if ( ctype_alpha($firstName) OR ctype_alpha($secondName)) {
  19.             if (filter_var($email, FILTER_VALIDATE_EMAIL)) {
  20.                 $sql = "INSERT INTO users (username, first_name, second_name, user_email, user_password) VALUES ('$username', '$firstName', '$secondName', '$email', '$password')";
  21.                 if ($conn->query($sql) === TRUE) {
  22.                     echo "Sign Up Successful";
  23.                 } else {
  24.                     error('input');
  25.                     // echo "Error: " . $sql . "<br>" . $conn->error;
  26.                 }
  27.                 $conn->close();
  28.  
  29.             }
  30.             else {
  31.                 error('email');
  32.             }
  33.         }
  34.         else {
  35.             error('name');
  36.         }
  37.        }
  38.        else {
  39.         error('username');
  40.        }
  41.     }
  42.     else {
  43.         error('password');
  44.     }
  45. }
  46. ?>
  47. <!DOCTYPE html>
  48. <html lang="en">
  49. <head>
  50.     <meta charset="UTF-8">
  51.     <meta name="viewport" content="width=device-width, initial-scale=1.0">
  52.     <meta http-equiv="X-UA-Compatible" content="ie=edge">
  53.     <title>Sign Up</title>
  54.     <link rel="stylesheet" href="../styles/main.css">
  55. </head>
  56. <body>
  57.     <div class="main-container">
  58.         <form action="" method="post">
  59.             <input type="text" name="username" placeholder="Username" maxlength="18" required>
  60.             <input type="text" name="firstName" placeholder="First Name" maxlength="18" required>
  61.             <input type="text" name="secondName" placeholder="Second Name" maxlength="18" required>
  62.             <input type="email" name="email" placeholder="Email" required>
  63.             <input type="password" name="password1" placeholder="Password" required>
  64.             <input type="password" name="password2" placeholder="Re-type Password" required>
  65.             <br>
  66.             <input type="submit" name="submit" value="Submit">
  67.         </form>
  68.     </div>
  69. </body>
  70. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement