Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php require_once('connection.php'); ?>
- <?php
- function error($error) {
- header('Location: sign_up.php?error=' . $error);
- exit();
- }
- if (isset($_POST['submit'])) {
- $username = $_POST['username'];
- $firstName = $_POST['firstName'];
- $secondName = $_POST['secondName'];
- $email = $_POST['email'];
- if ($_POST['password1'] == $_POST['password2']) {
- $password = password_hash($_POST['password1'], PASSWORD_DEFAULT);
- if ( ctype_alnum($username)) {
- if ( ctype_alpha($firstName) OR ctype_alpha($secondName)) {
- if (filter_var($email, FILTER_VALIDATE_EMAIL)) {
- $sql = "INSERT INTO users (username, first_name, second_name, user_email, user_password) VALUES ('$username', '$firstName', '$secondName', '$email', '$password')";
- if ($conn->query($sql) === TRUE) {
- echo "Sign Up Successful";
- } else {
- error('input');
- // echo "Error: " . $sql . "<br>" . $conn->error;
- }
- $conn->close();
- }
- else {
- error('email');
- }
- }
- else {
- error('name');
- }
- }
- else {
- error('username');
- }
- }
- else {
- error('password');
- }
- }
- ?>
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <meta http-equiv="X-UA-Compatible" content="ie=edge">
- <title>Sign Up</title>
- <link rel="stylesheet" href="../styles/main.css">
- </head>
- <body>
- <div class="main-container">
- <form action="" method="post">
- <input type="text" name="username" placeholder="Username" maxlength="18" required>
- <input type="text" name="firstName" placeholder="First Name" maxlength="18" required>
- <input type="text" name="secondName" placeholder="Second Name" maxlength="18" required>
- <input type="email" name="email" placeholder="Email" required>
- <input type="password" name="password1" placeholder="Password" required>
- <input type="password" name="password2" placeholder="Re-type Password" required>
- <br>
- <input type="submit" name="submit" value="Submit">
- </form>
- </div>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement