Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- session_start();
- //check if logged in
- if (isset($_SESSION['id'])){
- header("Location: index.php");
- }
- if (isset($_POST['register'])){
- include_once("db.php");
- $username = strip_tags($_POST['username']);
- $password = strip_tags($_POST['password']);
- $password_confirm = strip_tags($_POST['password_confirm']);
- $email = strip_tags($_POST['email']);
- $username = stripslashes($username);
- $password = stripslashes($password);
- $password_confirm = stripslashes($password_confirm);
- $email = stripslashes($email);
- $username = mysqli_real_escape_string($db, $username);
- $password = mysqli_real_escape_string($db, $password);
- $password_confirm = mysqli_real_escape_string($db, $password_confirm);
- $email = mysqli_real_escape_string($db, $email);
- //encrypt the password
- $password = md5($password);
- $password_confirm = md5($password_confirm);
- //sql storage queries
- $sql_store = "INSERT into users (username, password, email) VALUES ('$username','$password','$email')";
- $sql_fetch_username = "SELECT username FROM users WHERE username='$username'";
- $sql_fetch_email = "SELECT email FROM users WHERE email='$email'";
- //setting up queries
- $query_username = mysqli_query($db, $sql_fetch_username);
- $query_email = mysqli_query($db, $sql_fetch_email);
- //check for matches, incomplete entry, errors or for email already in use
- if(mysqli_num_rows($query_username)){
- echo"There is already a user with that name!";
- return;
- }
- if($username == ""){
- echo"Please enter a username!";
- return;
- }
- if($password == "" || $password_confirm==""){
- echo"Please enter your password!";
- return;
- }
- if($password !=$password_confirm){
- echo"The passwords do not match!";
- return;
- }
- if (!filter_var($email, FILTER_VALIDATE_EMAIL) || $email ==""){
- echo"This email is not valid!";
- return;
- }
- if (mysqli_num_rows($query_email)){
- echo"That email is already in use!";
- return;
- }
- mysqli_query($db, $sql_store);
- header("Location: index.php");
- ?>
- <!DOCTYPE html>
- <html>
- <head>
- <title>PQ</title>
- <link rel="stylesheet" type="text/css" href="style.css">
- <script src="main.js"></script>
- </head>
- <body>
- <div data-role="page" id="Welcome">
- <div data-role="header">
- <h1>Welcome</h1>
- </div>
- <div role="main" id="loginform">
- <form method="post" action="register.php" enctype="multipart/form-data">
- <input name="username" placeholder="Username" type="text">
- <input name="password" placeholder="Password" type="password">
- <input name="password_confirm" placeholder="Confirm Password" type="password">
- <input name="email" placeholder="Email address" type="text">
- <input name="register" type="submit" value="Register">
- </form>
- </div>
- <div data-role="footer" data-position="fixed" data-theme="c">
- <h4>(C) 2016</h4>
- </div>
- </div>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement