PHP: Registration Form




The code used for index.php is below:


<!DOCTYPE html>
<html lang="en">
<head>
    <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">
    <title>PHP: Registration Form</title>
</head>
<body>

    <h1 class="lesson-h1">PHP: Registration Form</h1>

    <?php

        include('../connection.php');

        $email = htmlentities($_POST['user-email']);
        $password = htmlentities($_POST['user-password']);
        $hashed_password = md5(md5($password));

        $new_user = [];

        if(isset($_POST['register'])){
            $sql = "SELECT * FROM `users` WHERE email = '$email'";
            $result = mysqli_query($link, $sql); 
            $result = mysqli_fetch_assoc($result);
            // echo var_dump($result);

            if(strlen($email) > 30){
                $err = "<h3>Email Address Too Long | Max Chars = 30</h3>";
                echo "<h3>" . $err . "</h3>";
            } else if(strlen($password) > 12){
                $err = "<h3>Password Too Long | Max Chars = 12</h3>";
                echo "<h3>" . $err . "</h3>";
            } else {
                if($email === $result['email']){
                    $err = "<h3>Email Address Already Registered</h3>";
                    echo "<h3>" . $err . "</h3>";
                } else {
                    array_push($new_user, $email, $hashed_password);
                    $sql = "INSERT INTO `users` (`email`, `pass`) VALUES ('$email', '$hashed_password')";
                    mysqli_query($link, $sql); 
                    echo "<h3>You Have Been Registered</h3>";
                }
            }
        }

    ?>

    <form action="index.php" method="post">
        <input type="email" name="user-email" id="user-email" placeholder="Email">
        <input type="password" name="user-password" id="user-password" placeholder="Password"><br>
        <input type="submit" name="register" value="Register">
    </form>
    <hr>    
    <?php
        include('../show_code.php');
        show_code('index.php');
    ?>

</body>
</html>