Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- include "config.php";
- if(isset($_POST['submit'])){
- $email = mysqli_real_escape_string($conn, $_POST['email']);
- $password = md5($_POST['password']);
- $ConfirmPassword = md5($_POST['ConfirmPassword']);
- $fname = mysqli_real_escape_string($conn, $_POST['fname']);
- $lname = mysqli_real_escape_string($conn, $_POST['lname']);
- $address = mysqli_real_escape_string($conn, $_POST['address']);
- $age = ($_POST['age']);
- $birthdate = ($_POST['birthdate']);
- $regdate = ($_POST['registration_date']);
- $select = " SELECT * FROM users WHERE email = '$email' && password = '$password' ";
- $selectEmail = " SELECT * FROM users WHERE email = '$email' ";
- $result = mysqli_query($conn, $select);
- $EmailQueryResult = mysqli_query($conn, $selectEmail);
- $passwordLength = strlen($password);
- if (mysqli_num_rows($result) > 0) {
- $error[] = "user already exists! ";
- }
- else if (mysqli_num_rows($EmailQueryResult) > 0) {
- $error[] = "email already used! ";
- }
- else {
- if ($password != $ConfirmPassword) {
- $error[] = "Passwords do not match! ";
- }
- // NEEDS REVISION
- else if ($passwordLength < 8) {
- $error[] = "Password should be at least 8 characters long";
- }else if ($age < 18) {
- $error[] = "You must be 18 years old & above to register";
- }else{
- $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')";
- mysqli_query($conn, $insert);
- header('location:login.php');
- }
- }
- }
- ?>
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <link rel="icon" type="image/x-icon" href="favicon1.ico">
- <title> Create an Account</title>
- <meta charset="UTF-8">
- <meta http-equiv="X-UA-Compatible" content="IE=edge">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <link rel="stylesheet" href = "styles.css">
- <link rel="icon" type="image/x-icon" href="favicon1.ico">
- </head>
- <body>
- <div class = "form-container" >
- <div class = "content" >
- <form method = "post">
- <?php
- if(isset($error)){
- foreach ($error as $error) {
- echo '<span class = "error-msg">'.$error.'<span>' ;
- }
- }
- ?>
- <img src="fairplay_logo.png" alt="" style="width:250px">
- <h1> CREATE AN ACCOUNT </h1>
- <input type="text" name = "email" required placeholder="E-mail">
- <input type="password" name = "password" required placeholder="Password">
- <input type="password" name = "ConfirmPassword" required placeholder="Confirm password">
- <input type="text" name = "fname" required placeholder="Enter first name">
- <input type="text" name = "lname" required placeholder="Enter last name">
- <input type="text" name = "address" id="addressInput" required placeholder="Enter full ddress">
- <p> Birthdate</p>
- <input type="date" name = "birthdate" id="birthdate" required placeholder="Enter birthdate">
- <p> Date of registration </p>
- <input type="date" name = "registration_date" required placeholder="Enter registration date">
- <input type="number" name = "age" id="age" required placeholder="Enter age">
- <input type="submit" name = "submit" id="submit">
- <h4>Already have an account? </h4>
- <a href="login.php">Login</a>
- <h4> Return to</h4> <a href="index.php"> homepage</a>
- </form>
- </div>
- </div>
- <!-- Auto computes for the age -->
- <script>
- // Retrieve the birthdate input element
- var birthdateInput = document.getElementById('birthdate');
- // Retrieve the age input element
- var ageInput = document.getElementById("age");
- // Attach an event listener to the input element
- birthdateInput.addEventListener('change', function() {
- // Retrieve the selected birthdate value
- var birthdate = new Date(this.value);
- // Retrieve the current date
- var currentDate = new Date();
- // Calculate the age
- var age = currentDate.getFullYear() - birthdate.getFullYear();
- // Update the age input field with the calculated age
- ageInput.value = age;
- });
- </script>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement