Advertisement
nailacrooc12

register

Jun 21st, 2023
5,253
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.36 KB | None | 0 0
  1. <?php
  2. include "config.php";
  3.  
  4. if(isset($_POST['submit'])){
  5.  
  6.     $email = mysqli_real_escape_string($conn, $_POST['email']);
  7.     $password = md5($_POST['password']);
  8.     $ConfirmPassword = md5($_POST['ConfirmPassword']);
  9.    
  10.     $fname = mysqli_real_escape_string($conn, $_POST['fname']);
  11.     $lname = mysqli_real_escape_string($conn, $_POST['lname']);
  12.     $address = mysqli_real_escape_string($conn, $_POST['address']);
  13.     $age = ($_POST['age']);
  14.     $birthdate = ($_POST['birthdate']);
  15.     $regdate = ($_POST['registration_date']);
  16.  
  17.     $select = " SELECT * FROM users WHERE email = '$email' && password = '$password' ";
  18.     $selectEmail = " SELECT * FROM users WHERE email = '$email' ";
  19.  
  20.     $result  = mysqli_query($conn, $select);
  21.     $EmailQueryResult = mysqli_query($conn, $selectEmail);
  22.     $passwordLength = strlen($password);
  23.  
  24.     if (mysqli_num_rows($result) > 0) {
  25.  
  26.         $error[] = "user already exists! ";
  27.  
  28.     }
  29.  
  30.     else if (mysqli_num_rows($EmailQueryResult) > 0) {
  31.         $error[] = "email already used! ";
  32.     }
  33.  
  34.     else {
  35.         if ($password != $ConfirmPassword) {
  36.             $error[] = "Passwords do not match! ";
  37.         }
  38.        
  39.         // NEEDS REVISION
  40.         else if ($passwordLength < 8) {
  41.             $error[] = "Password should be at least 8 characters long";
  42.         }else if ($age < 18) {
  43.             $error[] = "You must be 18 years old & above to register";
  44.         }else{
  45.             $insert = "INSERT INTO users (email, password, lastname, firstname, address, birthdate, age, registration_date, user_type) VALUES ('$email', '$password', '$lname', '$fname', '$address', '$birthdate', '$age', '$regdate', 'Voter')";
  46.             mysqli_query($conn, $insert);
  47.             header('location:login.php');
  48.         }
  49.     }
  50.  
  51.    
  52.  
  53. }
  54.  
  55.  
  56. ?>
  57.  
  58.  
  59. <!DOCTYPE html>
  60. <html lang="en">
  61. <head>
  62.  
  63. <link rel="icon" type="image/x-icon" href="favicon1.ico">
  64.     <title> Create an Account</title>
  65.     <meta charset="UTF-8">
  66.     <meta http-equiv="X-UA-Compatible" content="IE=edge">
  67.     <meta name="viewport" content="width=device-width, initial-scale=1.0">
  68.     <link rel="stylesheet" href = "styles.css">
  69.     <link rel="icon" type="image/x-icon" href="favicon1.ico">
  70. </head>
  71. <body>
  72.  
  73. <div class = "form-container" >
  74.     <div class = "content" >
  75.  
  76.     <form  method = "post">
  77.         <?php
  78.         if(isset($error)){
  79.  
  80.              foreach ($error as $error) {
  81.                 echo '<span class = "error-msg">'.$error.'<span>' ;
  82.             }
  83.              
  84.         }
  85.         ?>
  86.          <img src="fairplay_logo.png" alt="" style="width:250px">
  87.  
  88. <h1> CREATE AN ACCOUNT </h1>
  89.  
  90.  
  91. <input type="text" name = "email" required placeholder="E-mail">  
  92. <input type="password" name = "password" required placeholder="Password">  
  93. <input type="password" name = "ConfirmPassword" required placeholder="Confirm password">
  94. <input type="text" name = "fname" required placeholder="Enter first name">
  95. <input type="text" name = "lname" required placeholder="Enter last name">    
  96. <input type="text" name = "address" id="addressInput" required placeholder="Enter full ddress">    
  97. <p> Birthdate</p>
  98. <input type="date" name = "birthdate" id="birthdate" required placeholder="Enter birthdate">    
  99. <p> Date of registration </p>
  100. <input type="date" name = "registration_date" required placeholder="Enter registration date">    
  101.  
  102. <input type="number" name = "age" id="age" required placeholder="Enter age">    
  103. <input type="submit" name = "submit" id="submit">
  104. <h4>Already have an account? </h4>    
  105. <a href="login.php">Login</a>
  106. <h4> Return to</h4> <a href="index.php"> homepage</a>
  107.  
  108.  
  109. </form>
  110.  
  111.  
  112.     </div>
  113. </div>
  114.  
  115. <!-- Auto computes for the age -->
  116. <script>
  117.  
  118.  
  119.   // Retrieve the birthdate input element
  120.   var birthdateInput = document.getElementById('birthdate');
  121.  
  122.   // Retrieve the age input element
  123.   var ageInput = document.getElementById("age");
  124.  
  125.   // Attach an event listener to the input element
  126.   birthdateInput.addEventListener('change', function() {
  127.     // Retrieve the selected birthdate value
  128.     var birthdate = new Date(this.value);
  129.  
  130.     // Retrieve the current date
  131.     var currentDate = new Date();
  132.  
  133.     // Calculate the age
  134.     var age = currentDate.getFullYear() - birthdate.getFullYear();
  135.  
  136.     // Update the age input field with the calculated age
  137.     ageInput.value = age;
  138.   });
  139. </script>
  140.  
  141.  
  142.    
  143. </body>
  144. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement