Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // Turn off error reporting
- error_reporting(0);
- // Report runtime errors
- error_reporting(E_ERROR | E_WARNING | E_PARSE);
- // Report all errors
- error_reporting(E_ALL);
- // Same as error_reporting(E_ALL);
- ini_set("error_reporting", E_ALL);
- // Report all errors except E_NOTICE
- error_reporting(E_ALL & ~E_NOTICE);
- include_once("connect.php");
- session_start();
- if(isset($_POST['submit'])){
- }
- if(!isset ($_SESSION['email'] )){
- echo'<li><a href="signup.php">Sign Up</a></li>';
- echo'<li><a href="auth.php">Login</a></li>';
- }
- else{
- if($_SESSION['email']){
- $con = mysqli_connect("localhost", "root", "" ,"jono_db") or die("We couldn't connect!");
- $query = mysqli_query($con,"SELECT * FROM users WHERE email='".$_SESSION['email']."'");
- $numrows = mysqli_num_rows($query);
- if($numrows != 0){
- while($row = mysqli_fetch_assoc($query)){
- $usertype = $row['is_admin'];
- if($usertype == 1){
- }
- }
- }
- }
- echo'<li><a href="logout.php">Logout</a></li>';
- }
- ?>
- <?php
- /* FIELDS ARE STILL EMPTY THIS CODE IS USED FOR HIDING PRECAUTIONAL PHP ERRORS MGS BECAUSE YOURE USING PHP AND HTML FORM IN 1 FILE*/
- require_once("connect.php");
- // Turn off error reporting
- error_reporting(0);
- // Report runtime errors
- error_reporting(E_ERROR | E_WARNING | E_PARSE);
- // Report all errors
- error_reporting(E_ALL);
- // Same as error_reporting(E_ALL);
- ini_set("error_reporting", E_ALL);
- // Report all errors except E_NOTICE
- error_reporting(E_ALL & ~E_NOTICE);
- /* FIELDS ARE STILL EMPTY THIS CODE IS USED FOR HIDING PRECAUTIONAL PHP ERRORS MGS BECAUSE YOURE USING PHP AND HTML FORM IN 1 FILE*/
- $firstname = $_POST['firstname'];
- $lastname = $_POST['lastname'];
- $email = $_POST['email'];
- $username = $_POST['username'];
- $gender = $_POST['gender'];
- /* ENCRYPT THE PASSWORD USING MD5 FUNCTION */
- $password = md5($_POST['password']);
- $passwordconfirm = md5($_POST['passwordconfirm']);
- $defaultUserType = '0';
- $usertype = $_POST['usertype'];
- /* CHECKS WHETHER THIS VARIABLES HAVE VALUES */
- if ($firstName && $lastName && $email && $username && $gender && $password && $passwordconfirm){
- /* CHECKS WHETHER EMAIL FIELD FOLLOWS THE RIGHT EMAIL FORMAT */
- if (preg_match("/^[_\.0-9a-zA-Z-]+@([0-9a-zA-Z][0-9a-zA-Z-]+\.)+[a-zA-Z]{2,6}$/i", $email)) {
- if (strlen($password) > 7) {
- if ($password == $passwordconfirm) {
- /* DATABASE CONNECTION */
- $con = mysqli_connect("localhost", "root", "" ,"jono_db") or die("We couldn't connect!");
- /* CHECKS IF THE INPUTED VALUE FOR FIRST NAME IS EXISTED ON THE DATABASE */
- $usernamechecker = mysqli_query($con,"SELECT firstname FROM users WHERE firstname='$firstname'");
- $count = mysqli_num_rows($usernamechecker);
- /* CHECKS IF THE INPUTED VALUE FOR EMAIL IS EXISTED ON THE DATABASE */
- $emailchecker = mysqli_query($con ,"SELECT email FROM users WHERE email ='$email'");
- $count2 = mysqli_num_rows($emailchecker);
- if($count != 0 || $count2 != 0){
- if($count != 0){
- echo "Username already exist! Please enter another user.";
- }
- else if($count2 != 0){
- echo"Email already exist! Please enter another user.";
- }
- }
- else{
- $con = mysqli_connect("localhost", "root", "" ,"jono_db") or die("We couldn't connect!");
- $query = mysqli_query($con,"SELECT * FROM users WHERE email='".$_SESSION['email']."'");
- $numrows = mysqli_num_rows($query);
- /* START */
- /* THIS LINES OF CODES ARE USED TO CHECK IF THE USER IS AN ADMIN OR NON ADMIN*/
- if(isset($_SESSION['email'])){
- if($numrows != 0){
- while($row = mysqli_fetch_assoc($query)){
- $usertype = $row['is_admin'];
- if($usertype == 1){
- $query = "INSERT INTO `users`('',`username`, `password`, `email`, `firstname`, `lastname`, `gender`, `is_admin`) VALUES ('$firstname','$lastame','$email','$username','$password','$gender','$usertype')";
- $result = mysqli_query($con,$query);
- echo'Successfully created an account';
- }
- }
- }
- }
- /* END */
- /* INSERT THE VALID INPUTED VALUES IN THE TABLE USERS */
- $query = "INSERT INTO `users`('',`username`, `password`, `email`, `firstname`, `lastname`, `gender`, `is_admin`) VALUES ('$firstname','$lastame','$email','$username','$password','$gender','$defaultUserType')";
- $result = mysqli_query($con,$query);
- if($result){
- echo'<h3 color="red">Successfully created an account</h3>';
- }
- }
- }
- else {
- echo 'Your password does not match.';
- }
- }
- else{
- echo "Your password is too short! You need to type a password between 4 and 15 characters!";
- }
- }
- }
- ?>
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <?php include('header.php'); ?>
- </head>
- <body>
- <?php include('navigation.php'); ?>
- <form method="POST" action="signup.php">
- <div id="loginsignup">
- <!-- LOGIN PAGE -->
- <!-- REGISTRATION FORM -->
- <div class="text-center" style="padding:50px 0">
- <div class="logo">register</div>
- <!-- Main Form -->
- <div class="login-form-1">
- <form id="register-form" class="text-left">
- <div class="login-form-main-message"></div>
- <div class="main-login-form">
- <div class="login-group">
- <div class="form-group">
- <label for="reg_username" class="sr-only">Username</label>
- <input type="text" class="form-control" id="reg_username" name="username" placeholder="Username">
- </div>
- <div class="form-group">
- <label for="reg_password" class="sr-only">Password</label>
- <input type="password" class="form-control" id="reg_password" name="password" placeholder="Password">
- </div>
- <div class="form-group">
- <label for="reg_password_confirm" class="sr-only">Password Confirm</label>
- <input type="password" class="form-control" id="reg_password_confirm" name="passwordconfirm" placeholder="Confirm Password">
- </div>
- <div class="form-group">
- <label for="reg_email" class="sr-only">Email</label>
- <input type="text" class="form-control" id="reg_email" name="email" placeholder="Email">
- </div>
- <div class="form-group">
- <label for="reg_firstname" class="sr-only">First Name</label>
- <input type="text" class="form-control" id="reg_firstname" name="firstname" placeholder="First Name">
- </div>
- <div class="form-group">
- <label for="reg_lastname" class="sr-only">Last Name</label>
- <input type="text" class="form-control" id="reg_lastname" name="lastname" placeholder="Last Name">
- </div>
- <div class="form-group login-group-checkbox">
- <input type="radio" class="" name="reg_gender" id="male" placeholder="username">
- <label for="male">Male</label>
- <input type="radio" class="" name="reg_gender" id="female" placeholder="username">
- <label for="female">Female</label>
- </div>
- <div class="form-group login-group-checkbox">
- <input type="checkbox" class="tickbox" id="reg_agree" name="reg_agree" value="1"/>
- <label for="reg_agree">I agree with terms and conditions <a href="#">terms</a></label>
- </div>
- </div>
- <?php
- /* FIELDS ARE STILL EMPTY THIS CODE IS USED FOR HIDING PRECAUTIONAL PHP ERRORS MGS BECAUSE YOURE USING PHP AND HTML FORM IN 1 FILE*/
- require_once("connect.php");
- // Turn off error reporting
- error_reporting(0);
- // Report runtime errors
- error_reporting(E_ERROR | E_WARNING | E_PARSE);
- // Report all errors
- error_reporting(E_ALL);
- // Same as error_reporting(E_ALL);
- ini_set("error_reporting", E_ALL);
- // Report all errors except E_NOTICE
- error_reporting(E_ALL & ~E_NOTICE);
- /* FIELDS ARE STILL EMPTY THIS CODE IS USED FOR HIDING PRECAUTIONAL PHP ERRORS MGS BECAUSE YOURE USING PHP AND HTML FORM IN 1 FILE*/
- /* START */
- /* THIS LINE OF CODES , CHECKS WHETHER THERE IS CURRENTLY LOGGED IN USER AND WHETHER
- ITS AN ADMIN OR NON ADMIN*/
- if(isset($_SESSION['email'])){
- if($_SESSION['email']){
- $con = mysqli_connect("localhost", "root", "" ,"jono_db") or die("We couldn't connect!");
- $query = mysqli_query($con,"SELECT * FROM users WHERE email='".$_SESSION['email']."'");
- $numrows = mysqli_num_rows($query);
- if($numrows != 0){
- while($row = mysqli_fetch_assoc($query)){
- $usertype = $row['is_admin'];
- if($usertype == 1){
- echo'<label>User Type:</label><br/>';
- echo'<select name="usertype">';
- echo'<option value="1">ADMIN</option>';
- echo'<option value="0">NON ADMIN</option>';
- echo'</select>';
- }
- else{
- header('Location: home.php');
- }
- }
- }
- }
- }
- ?>
- <button type="submit" name="submit" class="login-button"><i class="fa fa-chevron-right"></i></button>
- </div>
- <div class="etc-login-form">
- <p>Already have an account? <a href="auth.php">Login Here</a></p>
- </div>
- </form>
- </div>
- <!-- end:Main Form -->
- </div>
- </div>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement